Upgrade to 3.8.0

This commit is contained in:
Bastian Allgeier
2022-10-06 10:11:54 +02:00
parent a9ed4e45ca
commit 7d168aae58
332 changed files with 26337 additions and 21977 deletions

View File

@@ -2,6 +2,7 @@
use Kirby\Cms\App;
use Kirby\Cms\Blocks;
use Kirby\Cms\Content;
use Kirby\Cms\Field;
use Kirby\Cms\Files;
use Kirby\Cms\Html;
@@ -63,16 +64,16 @@ return function (App $app) {
*/
'toBlocks' => function (Field $field) {
try {
$blocks = Blocks::factory(Blocks::parse($field->value()), [
'parent' => $field->parent(),
$blocks = Blocks::parse($field->value());
$blocks = Blocks::factory($blocks, [
'parent' => $field->parent()
]);
return $blocks->filter('isHidden', false);
} catch (Throwable $e) {
if ($field->parent() === null) {
$message = 'Invalid blocks data for "' . $field->key() . '" field';
} else {
$message = 'Invalid blocks data for "' . $field->key() . '" field on parent "' . $field->parent()->title() . '"';
} catch (Throwable) {
$message = 'Invalid blocks data for "' . $field->key() . '" field';
if ($parent = $field->parent()) {
$message .= ' on parent "' . $parent->title() . '"';
}
throw new InvalidArgumentException($message);
@@ -99,13 +100,10 @@ return function (App $app) {
* @return array
*/
'toData' => function (Field $field, string $method = ',') {
switch ($method) {
case 'yaml':
case 'json':
return Data::decode($field->value, $method);
default:
return $field->split($method);
}
return match ($method) {
'yaml', 'json' => Data::decode($field->value, $method),
default => $field->split($method)
};
},
/**
@@ -222,6 +220,17 @@ return function (App $app) {
return Html::a($href, $field->value, $attr ?? []);
},
/**
* Parse yaml data and convert it to a
* content object
*
* @param \Kirby\Cms\Field $field
* @return \Kirby\Cms\Content
*/
'toObject' => function (Field $field) {
return new Content($field->yaml(), $field->parent(), true);
},
/**
* Returns a page object from a page id in the field
*
@@ -252,11 +261,11 @@ return function (App $app) {
'toStructure' => function (Field $field) {
try {
return new Structure(Data::decode($field->value, 'yaml'), $field->parent());
} catch (Exception $e) {
if ($field->parent() === null) {
$message = 'Invalid structure data for "' . $field->key() . '" field';
} else {
$message = 'Invalid structure data for "' . $field->key() . '" field on parent "' . $field->parent()->title() . '"';
} catch (Exception) {
$message = 'Invalid structure data for "' . $field->key() . '" field';
if ($parent = $field->parent()) {
$message .= ' on parent "' . $parent->title() . '"';
}
throw new InvalidArgumentException($message);
@@ -500,10 +509,11 @@ return function (App $app) {
*
* @param \Kirby\Cms\Field $field
* @param array $data
* @param string $fallback Fallback for tokens in the template that cannot be replaced
* @param string|null $fallback Fallback for tokens in the template that cannot be replaced
* (`null` to keep the original token)
* @return \Kirby\Cms\Field
*/
'replace' => function (Field $field, array $data = [], string $fallback = '') use ($app) {
'replace' => function (Field $field, array $data = [], string|null $fallback = '') use ($app) {
if ($parent = $field->parent()) {
// never pass `null` as the $template to avoid the fallback to the model ID
$field->value = $parent->toString($field->value ?? '', $data, $fallback);