Upgrade to 3.6.0

This commit is contained in:
Bastian Allgeier
2021-11-16 14:53:37 +01:00
parent 7388fa4d24
commit 92b7a330fa
318 changed files with 20017 additions and 6878 deletions

View File

@@ -22,6 +22,8 @@ class Block extends Item
{
const ITEMS_CLASS = '\Kirby\Cms\Blocks';
use HasMethods;
/**
* @var \Kirby\Cms\Content
*/
@@ -32,6 +34,13 @@ class Block extends Item
*/
protected $isHidden;
/**
* Registry with all block models
*
* @var array
*/
public static $models = [];
/**
* @var string
*/
@@ -46,6 +55,11 @@ class Block extends Item
*/
public function __call(string $method, array $args = [])
{
// block methods
if ($this->hasMethod($method)) {
return $this->callMethod($method, $args);
}
return $this->content()->get($method);
}
@@ -53,7 +67,7 @@ class Block extends Item
* Creates a new block object
*
* @param array $params
* @param \Kirby\Cms\Blocks $siblings
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function __construct(array $params)
{
@@ -69,7 +83,7 @@ class Block extends Item
$this->content = $params['content'] ?? [];
$this->isHidden = $params['isHidden'] ?? false;
$this->type = $params['type'] ?? null;
$this->type = $params['type'];
// create the content object
$this->content = new Content($this->content, $this->parent);
@@ -89,13 +103,13 @@ class Block extends Item
* Deprecated method to return the block type
*
* @deprecated 3.5.0 Use `\Kirby\Cms\Block::type()` instead
* @todo Add deprecated() helper warning in 3.6.0
* @todo Remove in 3.7.0
*
* @return string
*/
public function _key(): string
{
deprecated('Block::_key() has been deprecated. Use Block::type() instead.');
return $this->type();
}
@@ -103,13 +117,13 @@ class Block extends Item
* Deprecated method to return the block id
*
* @deprecated 3.5.0 Use `\Kirby\Cms\Block::id()` instead
* @todo Add deprecated() helper warning in 3.6.0
* @todo Remove in 3.7.0
*
* @return string
*/
public function _uid(): string
{
deprecated('Block::_uid() has been deprecated. Use Block::id() instead.');
return $this->id();
}
@@ -154,6 +168,38 @@ class Block extends Item
return Str::excerpt($this->toHtml(), ...$args);
}
/**
* Constructs a block object with registering blocks models
*
* @param array $params
* @return static
* @throws \Kirby\Exception\InvalidArgumentException
* @internal
*/
public static function factory(array $params)
{
$type = $params['type'] ?? null;
if (empty($type) === false && $class = (static::$models[$type] ?? null)) {
$object = new $class($params);
if (is_a($object, 'Kirby\Cms\Block') === true) {
return $object;
}
}
// default model for blocks
if ($class = (static::$models['Kirby\Cms\Block'] ?? null)) {
$object = new $class($params);
if (is_a($object, 'Kirby\Cms\Block') === true) {
return $object;
}
}
return new static($params);
}
/**
* Checks if the block is empty
*