Update Composer packages

This commit is contained in:
Paul Nicoué 2022-12-19 14:56:05 +01:00
parent 0320235f6c
commit a8b68fb61b
378 changed files with 28466 additions and 28852 deletions

View file

@ -46,7 +46,6 @@ return [
'cookie' => 'Kirby\Http\Cookie',
'header' => 'Kirby\Http\Header',
'remote' => 'Kirby\Http\Remote',
'server' => 'Kirby\Http\Server',
// image classes
'dimensions' => 'Kirby\Image\Dimensions',

View file

@ -57,6 +57,7 @@ return [
},
'type' => fn (File $file) => $file->type(),
'url' => fn (File $file) => $file->url(),
'uuid' => fn (File $file) => $file->uuid()?->toString()
],
'type' => 'Kirby\Cms\File',
'views' => [
@ -79,7 +80,8 @@ return [
'size',
'template',
'type',
'url'
'url',
'uuid'
],
'compact' => [
'filename',
@ -87,6 +89,7 @@ return [
'link',
'type',
'url',
'uuid'
],
'panel' => [
'blueprint',
@ -109,7 +112,8 @@ return [
'prevWithTemplate' => 'compact',
'template',
'type',
'url'
'url',
'uuid'
]
],
];

View file

@ -1,6 +1,5 @@
<?php
use Kirby\Cms\Helpers;
use Kirby\Cms\Page;
use Kirby\Form\Form;
@ -21,54 +20,25 @@ return [
'hasFiles' => fn (Page $page) => $page->hasFiles(),
'id' => fn (Page $page) => $page->id(),
'isSortable' => fn (Page $page) => $page->isSortable(),
/**
* @deprecated 3.6.0
* @todo Remove in 3.8.0
* @codeCoverageIgnore
*/
'next' => function (Page $page) {
Helpers::deprecated('The API field page.next has been deprecated and will be removed in 3.8.0.');
return $page
->nextAll()
->filter('intendedTemplate', $page->intendedTemplate())
->filter('status', $page->status())
->filter('isReadable', true)
->first();
},
'num' => fn (Page $page) => $page->num(),
'options' => fn (Page $page) => $page->panel()->options(['preview']),
'panelImage' => fn (Page $page) => $page->panel()->image(),
'parent' => fn (Page $page) => $page->parent(),
'parents' => fn (Page $page) => $page->parents()->flip(),
/**
* @deprecated 3.6.0
* @todo Remove in 3.8.0
* @codeCoverageIgnore
*/
'prev' => function (Page $page) {
Helpers::deprecated('The API field page.prev has been deprecated and will be removed in 3.8.0.');
return $page
->prevAll()
->filter('intendedTemplate', $page->intendedTemplate())
->filter('status', $page->status())
->filter('isReadable', true)
->last();
},
'previewUrl' => fn (Page $page) => $page->previewUrl(),
'siblings' => function (Page $page) {
'num' => fn (Page $page) => $page->num(),
'options' => fn (Page $page) => $page->panel()->options(['preview']),
'panelImage' => fn (Page $page) => $page->panel()->image(),
'parent' => fn (Page $page) => $page->parent(),
'parents' => fn (Page $page) => $page->parents()->flip(),
'previewUrl' => fn (Page $page) => $page->previewUrl(),
'siblings' => function (Page $page) {
if ($page->isDraft() === true) {
return $page->parentModel()->children()->not($page);
} else {
return $page->siblings();
}
return $page->siblings();
},
'slug' => fn (Page $page) => $page->slug(),
'status' => fn (Page $page) => $page->status(),
'template' => fn (Page $page) => $page->intendedTemplate()->name(),
'title' => fn (Page $page) => $page->title()->value(),
'url' => fn (Page $page) => $page->url(),
'uuid' => fn (Page $page) => $page->uuid()?->toString()
],
'type' => 'Kirby\Cms\Page',
'views' => [
@ -76,7 +46,8 @@ return [
'id',
'title',
'url',
'num'
'num',
'uuid'
],
'default' => [
'content',
@ -88,7 +59,8 @@ return [
'slug',
'template',
'title',
'url'
'url',
'uuid'
],
'panel' => [
'id',
@ -102,7 +74,8 @@ return [
'previewUrl',
'slug',
'title',
'url'
'url',
'uuid'
],
'selector' => [
'id',

View file

@ -32,28 +32,20 @@ return [
'slugs' => fn () => Str::$language,
'title' => fn () => $this->site()->title()->value(),
'translation' => function () {
if ($user = $this->user()) {
$translationCode = $user->language();
} else {
$translationCode = $this->kirby()->panelLanguage();
}
$code = $this->user()?->language() ??
$this->kirby()->panelLanguage();
if ($translation = $this->kirby()->translation($translationCode)) {
return $translation;
} else {
return $this->kirby()->translation('en');
}
return $this->kirby()->translation($code) ??
$this->kirby()->translation('en');
},
'kirbytext' => fn () => $this->kirby()->option('panel.kirbytext') ?? true,
'user' => fn () => $this->user(),
'version' => function () {
$user = $this->user();
if ($user && $user->role()->permissions()->for('access', 'system') === true) {
if ($this->user()?->role()->permissions()->for('access', 'system') === true) {
return $this->kirby()->version();
} else {
return null;
}
return null;
}
],
'type' => 'Kirby\Cms\System',

View file

@ -24,7 +24,8 @@ return [
'prev' => fn (User $user) => $user->prev(),
'role' => fn (User $user) => $user->role(),
'roles' => fn (User $user) => $user->roles(),
'username' => fn (User $user) => $user->username()
'username' => fn (User $user) => $user->username(),
'uuid' => fn (User $user) => $user->uuid()?->toString()
],
'type' => 'Kirby\Cms\User',
'views' => [
@ -39,7 +40,8 @@ return [
'options',
'prev' => 'compact',
'role',
'username'
'username',
'uuid'
],
'compact' => [
'avatar' => 'compact',
@ -48,7 +50,8 @@ return [
'language',
'name',
'role' => 'compact',
'username'
'username',
'uuid'
],
'auth' => [
'avatar' => 'compact',
@ -72,6 +75,7 @@ return [
'prev' => ['id', 'name'],
'role',
'username',
'uuid'
],
]
];

View file

@ -70,13 +70,11 @@ return [
$user = $auth->login($email, $password, $long);
}
} else {
if (isset($methods['code']) === true) {
$mode = 'login';
} elseif (isset($methods['password-reset']) === true) {
$mode = 'password-reset';
} else {
throw new InvalidArgumentException('Login without password is not enabled');
}
$mode = match (true) {
isset($methods['code']) => 'login',
isset($methods['password-reset']) => 'password-reset',
default => throw new InvalidArgumentException('Login without password is not enabled')
};
$status = $auth->createChallenge($email, $long, $mode);
}
@ -87,13 +85,13 @@ return [
'status' => 'ok',
'user' => $this->resolve($user)->view('auth')->toArray()
];
} else {
return [
'code' => 200,
'status' => 'ok',
'challenge' => $status->challenge()
];
}
return [
'code' => 200,
'status' => 'ok',
'challenge' => $status->challenge()
];
}
],
[
@ -105,4 +103,14 @@ return [
return true;
}
],
[
'pattern' => 'auth/ping',
'method' => 'POST',
'auth' => false,
'action' => function () {
// refresh the session timeout
$this->kirby()->session();
return true;
}
],
];

View file

@ -12,9 +12,7 @@ return [
'pattern' => $pattern . '/files/(:any)/sections/(:any)',
'method' => 'GET',
'action' => function (string $path, string $filename, string $sectionName) {
if ($section = $this->file($path, $filename)->blueprint()->section($sectionName)) {
return $section->toResponse();
}
return $this->file($path, $filename)->blueprint()->section($sectionName)?->toResponse();
}
],
[
@ -60,9 +58,9 @@ return [
if ($this->requestMethod() === 'GET') {
return $files->search($this->requestQuery('q'));
} else {
return $files->query($this->requestBody());
}
return $files->query($this->requestBody());
}
],
[
@ -86,16 +84,20 @@ return [
'pattern' => $pattern . '/files/(:any)',
'method' => 'PATCH',
'action' => function (string $path, string $filename) {
return $this->file($path, $filename)->update($this->requestBody(), $this->language(), true);
return $this->file($path, $filename)->update(
$this->requestBody(),
$this->language(),
true
);
}
],
[
'pattern' => $pattern . '/files/(:any)',
'method' => 'POST',
'action' => function (string $path, string $filename) {
return $this->upload(function ($source) use ($path, $filename) {
return $this->file($path, $filename)->replace($source);
});
return $this->upload(
fn ($source) => $this->file($path, $filename)->replace($source)
);
}
],
[
@ -124,9 +126,9 @@ return [
if ($this->requestMethod() === 'GET') {
return $files->search($this->requestQuery('q'));
} else {
return $files->query($this->requestBody());
}
return $files->query($this->requestBody());
}
],
];

View file

@ -29,18 +29,14 @@ return [
'pattern' => 'languages/(:any)',
'method' => 'PATCH',
'action' => function (string $code) {
if ($language = $this->kirby()->languages()->find($code)) {
return $language->update($this->requestBody());
}
return $this->kirby()->languages()->find($code)?->update($this->requestBody());
}
],
[
'pattern' => 'languages/(:any)',
'method' => 'DELETE',
'action' => function (string $code) {
if ($language = $this->kirby()->languages()->find($code)) {
return $language->delete();
}
return $this->kirby()->languages()->find($code)?->delete();
}
]
];

View file

@ -5,40 +5,41 @@
* Content Lock Routes
*/
return [
[
'pattern' => '(:all)/lock',
'method' => 'GET',
'action' => function (string $path) {
return [
'lock' => $this->parent($path)->lock()?->toArray() ?? false
];
}
],
[
'pattern' => '(:all)/lock',
'method' => 'PATCH',
'action' => function (string $path) {
if ($lock = $this->parent($path)->lock()) {
return $lock->create();
}
return $this->parent($path)->lock()?->create();
}
],
[
'pattern' => '(:all)/lock',
'method' => 'DELETE',
'action' => function (string $path) {
if ($lock = $this->parent($path)->lock()) {
return $lock->remove();
}
return $this->parent($path)->lock()?->remove();
}
],
[
'pattern' => '(:all)/unlock',
'method' => 'PATCH',
'action' => function (string $path) {
if ($lock = $this->parent($path)->lock()) {
return $lock->unlock();
}
return $this->parent($path)->lock()?->unlock();
}
],
[
'pattern' => '(:all)/unlock',
'method' => 'DELETE',
'action' => function (string $path) {
if ($lock = $this->parent($path)->lock()) {
return $lock->resolve();
}
return $this->parent($path)->lock()?->resolve();
}
],
];

View file

@ -104,9 +104,7 @@ return [
'pattern' => 'pages/(:any)/sections/(:any)',
'method' => 'GET',
'action' => function (string $id, string $sectionName) {
if ($section = $this->page($id)->blueprint()->section($sectionName)) {
return $section->toResponse();
}
return $this->page($id)->blueprint()->section($sectionName)?->toResponse();
}
],
[

View file

@ -10,14 +10,11 @@ return [
'action' => function () {
$kirby = $this->kirby();
switch ($kirby->request()->get('canBe')) {
case 'changed':
return $kirby->roles()->canBeChanged();
case 'created':
return $kirby->roles()->canBeCreated();
default:
return $kirby->roles();
}
return match ($kirby->request()->get('canBe')) {
'changed' => $kirby->roles()->canBeChanged(),
'created' => $kirby->roles()->canBeCreated(),
default => $kirby->roles()
};
}
],
[

View file

@ -79,18 +79,16 @@ return [
if ($this->requestMethod() === 'GET') {
return $pages->search($this->requestQuery('q'));
} else {
return $pages->query($this->requestBody());
}
return $pages->query($this->requestBody());
}
],
[
'pattern' => 'site/sections/(:any)',
'method' => 'GET',
'action' => function (string $sectionName) {
if ($section = $this->site()->blueprint()->section($sectionName)) {
return $section->toResponse();
}
return $this->site()->blueprint()->section($sectionName)?->toResponse();
}
],
[

View file

@ -17,19 +17,18 @@ return [
if ($this->kirby()->user()) {
return $system;
} else {
if ($system->isOk() === true) {
$info = $this->resolve($system)->view('login')->toArray();
} else {
$info = $this->resolve($system)->view('troubleshooting')->toArray();
}
return [
'status' => 'ok',
'data' => $info,
'type' => 'model'
];
}
$info = match ($system->isOk()) {
true => $this->resolve($system)->view('login')->toArray(),
false => $this->resolve($system)->view('troubleshooting')->toArray()
};
return [
'status' => 'ok',
'data' => $info,
'type' => 'model'
];
}
],
[

View file

@ -26,9 +26,9 @@ return [
'action' => function () {
if ($this->requestMethod() === 'GET') {
return $this->users()->search($this->requestQuery('q'));
} else {
return $this->users()->query($this->requestBody());
}
return $this->users()->query($this->requestBody());
}
],
[
@ -79,17 +79,16 @@ return [
],
'method' => 'POST',
'action' => function (string $id) {
if ($avatar = $this->user($id)->avatar()) {
$avatar->delete();
}
$this->user($id)->avatar()?->delete();
return $this->upload(function ($source, $filename) use ($id) {
return $this->user($id)->createFile([
return $this->upload(
fn ($source, $filename) => $this->user($id)->createFile([
'filename' => 'profile.' . F::extension($filename),
'template' => 'avatar',
'source' => $source
]);
}, $single = true);
]),
single: true
);
}
],
// @codeCoverageIgnoreEnd

View file

@ -1,48 +1,92 @@
<?php
use Kirby\Cms\App;
use Kirby\Toolkit\I18n;
return [
'system' => [
'pattern' => 'system',
'action' => function () {
$kirby = App::instance();
$system = $kirby->system();
$license = $system->license();
$kirby = App::instance();
$system = $kirby->system();
$updateStatus = $system->updateStatus();
$license = $system->license();
// @codeCoverageIgnoreStart
if ($license === true) {
// valid license, but user is not admin
$license = 'Kirby 3';
} elseif ($license === false) {
// no valid license
$license = null;
}
// @codeCoverageIgnoreEnd
$environment = [
[
'label' => $license ? I18n::translate('license') : I18n::translate('license.register.label'),
'value' => $license ? 'Kirby 3' : I18n::translate('license.unregistered.label'),
'theme' => $license ? null : 'negative',
'dialog' => $license ? 'license' : 'registration'
],
[
'label' => $updateStatus?->label() ?? I18n::translate('version'),
'value' => $kirby->version(),
'link' => (
$updateStatus ?
$updateStatus->url() :
'https://github.com/getkirby/kirby/releases/tag/' . $kirby->version()
),
'theme' => $updateStatus?->theme()
],
[
'label' => 'PHP',
'value' => phpversion()
],
[
'label' => I18n::translate('server'),
'value' => $system->serverSoftware() ?? '?'
]
];
$exceptions = $updateStatus?->exceptionMessages() ?? [];
$plugins = $system->plugins()->values(function ($plugin) use (&$exceptions) {
$authors = $plugin->authorsNames();
$updateStatus = $plugin->updateStatus();
$version = $updateStatus?->toArray() ?? $plugin->version() ?? '';
if ($updateStatus !== null) {
$exceptions = array_merge($exceptions, $updateStatus->exceptionMessages());
}
$plugins = $system->plugins()->values(function ($plugin) {
return [
'author' => $plugin->authorsNames(),
'license' => $plugin->license(),
'author' => empty($authors) ? '' : $authors,
'license' => $plugin->license() ?? '',
'name' => [
'text' => $plugin->name(),
'text' => $plugin->name() ?? '',
'href' => $plugin->link(),
],
'version' => $plugin->version(),
'version' => $version,
];
});
$security = $updateStatus?->messages() ?? [];
if ($kirby->option('debug', false) === true) {
$security[] = [
'id' => 'debug',
'text' => I18n::translate('system.issues.debug'),
'link' => 'https://getkirby.com/security/debug'
];
}
if ($kirby->environment()->https() !== true) {
$security[] = [
'id' => 'https',
'text' => I18n::translate('system.issues.https'),
'link' => 'https://getkirby.com/security/https'
];
}
return [
'component' => 'k-system-view',
'props' => [
'debug' => $kirby->option('debug', false),
'license' => $license,
'plugins' => $plugins,
'php' => phpversion(),
'server' => $system->serverSoftware(),
'https' => $kirby->environment()->https(),
'version' => $kirby->version(),
'urls' => [
'environment' => $environment,
'exceptions' => $kirby->option('debug') === true ? $exceptions : [],
'plugins' => $plugins,
'security' => $security,
'urls' => [
'content' => $system->exposedFileUrl('content'),
'git' => $system->exposedFileUrl('git'),
'kirby' => $system->exposedFileUrl('kirby'),

View file

@ -1,5 +1,10 @@
<?php /** @var \Kirby\Cms\Block $block */ ?>
<figure>
<?php
/** @var \Kirby\Cms\Block $block */
$caption = $block->caption();
$crop = $block->crop()->isTrue();
$ratio = $block->ratio()->or('auto');
?>
<figure<?= Html::attr(['data-ratio' => $ratio, 'data-crop' => $crop], null, ' ') ?>>
<ul>
<?php foreach ($block->images()->toFiles() as $image): ?>
<li>
@ -7,4 +12,9 @@
</li>
<?php endforeach ?>
</ul>
<?php if ($caption->isNotEmpty()): ?>
<figcaption>
<?= $caption ?>
</figcaption>
<?php endif ?>
</figure>

View file

@ -14,3 +14,27 @@ fields:
template: blocks/image
image:
ratio: 1/1
caption:
label: field.blocks.image.caption
type: writer
icon: text
inline: true
ratio:
label: field.blocks.image.ratio
type: select
placeholder: Auto
width: 1/2
options:
1/1: "1:1"
16/9: "16:9"
10/8: "10:8"
21/9: "21:9"
7/5: "7:5"
4/3: "4:3"
5/3: "5:3"
3/2: "3:2"
3/1: "3:1"
crop:
label: field.blocks.image.crop
type: toggle
width: 1/2

View file

@ -4,8 +4,9 @@ use Kirby\Cms\App;
use Kirby\Cms\Collection;
use Kirby\Cms\File;
use Kirby\Cms\FileVersion;
use Kirby\Cms\Helpers;
use Kirby\Cms\Page;
use Kirby\Cms\Template;
use Kirby\Cms\User;
use Kirby\Data\Data;
use Kirby\Email\PHPMailer as Emailer;
use Kirby\Filesystem\F;
@ -30,33 +31,6 @@ return [
*/
'css' => fn (App $kirby, string $url, $options = null): string => $url,
/**
* Object and variable dumper
* to help with debugging.
*
* @param \Kirby\Cms\App $kirby Kirby instance
* @param mixed $variable
* @param bool $echo
* @return string
*
* @deprecated 3.7.0 Disable `dump()` via `KIRBY_HELPER_DUMP` instead and create your own function
* @todo move to `Helpers::dump()`, remove component in 3.8.0
*/
'dump' => function (App $kirby, $variable, bool $echo = true) {
if ($kirby->environment()->cli() === true) {
$output = print_r($variable, true) . PHP_EOL;
} else {
$output = '<pre>' . print_r($variable, true) . '</pre>';
}
if ($echo === true) {
echo $output;
}
return $output;
},
/**
* Add your own email provider
*
@ -108,7 +82,7 @@ return [
Data::write($job, array_merge($options, [
'filename' => $file->filename()
]));
} catch (Throwable $e) {
} catch (Throwable) {
// if thumb doesn't exist yet and job file cannot
// be created, return
return $file;
@ -138,24 +112,16 @@ return [
* @param \Kirby\Cms\App $kirby Kirby instance
* @param string $text Text to parse
* @param array $options Markdown options
* @param bool $inline Whether to wrap the text in `<p>` tags (deprecated: set via $options['inline'] instead)
* @return string
* @todo remove $inline parameter in in 3.8.0
*/
'markdown' => function (App $kirby, string $text = null, array $options = [], bool $inline = false): string {
'markdown' => function (
App $kirby,
string $text = null,
array $options = []
): string {
static $markdown;
static $config;
// warning for deprecated fourth parameter
if (func_num_args() === 4 && isset($options['inline']) === false) {
// @codeCoverageIgnoreStart
Helpers::deprecated('markdown component: the $inline parameter is deprecated and will be removed in Kirby 3.8.0. Use $options[\'inline\'] instead.');
// @codeCoverageIgnoreEnd
}
// support for the deprecated fourth argument
$options['inline'] ??= $inline;
// if the config options have changed or the component is called for the first time,
// (re-)initialize the parser object
if ($config !== $options) {
@ -206,17 +172,22 @@ return [
return $options['words'] ? '\b' . preg_quote($value) . '\b' : preg_quote($value);
}, $searchWords);
// returns an empty collection if there is no search word
if (empty($searchWords) === true) {
return $collection->limit(0);
}
$preg = '!(' . implode('|', $searchWords) . ')!i';
$results = $collection->filter(function ($item) use ($query, $preg, $options, $lowerQuery, $exactQuery) {
$data = $item->content()->toArray();
$keys = array_keys($data);
$keys[] = 'id';
if (is_a($item, 'Kirby\Cms\User') === true) {
if ($item instanceof User) {
$keys[] = 'name';
$keys[] = 'email';
$keys[] = 'role';
} elseif (is_a($item, 'Kirby\Cms\Page') === true) {
} elseif ($item instanceof Page) {
// apply the default score for pages
$options['score'] = array_merge([
'id' => 64,
@ -295,9 +266,8 @@ return [
* @param \Kirby\Cms\App $kirby Kirby instance
* @param string|array $name Snippet name
* @param array $data Data array for the snippet
* @return string|null
*/
'snippet' => function (App $kirby, $name, array $data = []): ?string {
'snippet' => function (App $kirby, $name, array $data = []): string {
$snippets = A::wrap($name);
foreach ($snippets as $name) {

View file

@ -46,13 +46,13 @@ return [
/**
* Latest date, which can be selected/saved (Y-m-d)
*/
'max' => function (string $max = null): ?string {
'max' => function (string $max = null): string|null {
return Date::optional($max);
},
/**
* Earliest date, which can be selected/saved (Y-m-d)
*/
'min' => function (string $min = null): ?string {
'min' => function (string $min = null): string|null {
return Date::optional($min);
},

View file

@ -34,7 +34,10 @@ return [
],
'computed' => [
'parentModel' => function () {
if (is_string($this->parent) === true && $model = $this->model()->query($this->parent, 'Kirby\Cms\Model')) {
if (
is_string($this->parent) === true &&
$model = $this->model()->query($this->parent, 'Kirby\Cms\Model')
) {
return $model;
}
@ -68,10 +71,13 @@ return [
foreach (Data::decode($value, 'yaml') as $id) {
if (is_array($id) === true) {
$id = $id['id'] ?? null;
$id = $id['uuid'] ?? $id['id'] ?? null;
}
if ($id !== null && ($file = $this->kirby()->file($id, $this->model()))) {
if (
$id !== null &&
($file = $this->kirby()->file($id, $this->model()))
) {
$files[] = $this->fileResponse($file);
}
}
@ -122,7 +128,7 @@ return [
];
},
'save' => function ($value = null) {
return A::pluck($value, 'uuid');
return A::pluck($value, $this->store);
},
'validations' => [
'max',

View file

@ -1,6 +1,6 @@
<?php
use Kirby\Form\Options;
use Kirby\Field\FieldOptions;
return [
'props' => [
@ -30,19 +30,18 @@ return [
],
'methods' => [
'getOptions' => function () {
return Options::factory(
$this->options(),
$this->props,
$this->model()
);
$props = FieldOptions::polyfill($this->props);
$options = FieldOptions::factory($props['options']);
return $options->render($this->model());
},
'sanitizeOption' => function ($option) {
$allowed = array_column($this->options(), 'value');
return in_array($option, $allowed, true) === true ? $option : null;
'sanitizeOption' => function ($value) {
$options = array_column($this->options(), 'value');
return in_array($value, $options, true) === true ? $value : null;
},
'sanitizeOptions' => function ($options) {
$allowed = array_column($this->options(), 'value');
return array_intersect($options, $allowed);
'sanitizeOptions' => function ($values) {
$options = array_column($this->options(), 'value');
$options = array_intersect($values, $options);
return array_values($options);
},
]
];

View file

@ -1,6 +1,7 @@
<?php
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
return [
'props' => [
@ -67,12 +68,21 @@ return [
return $search;
},
/**
* Whether to store UUID or ID in the
* content file of the model
*
* @param string $store 'uuid'|'id'
*/
'store' => function (string $store = 'uuid') {
return Str::lower($store);
},
/**
* Main text for each item
*/
'text' => function (string $text = null) {
return $text;
},
],
];

View file

@ -51,7 +51,7 @@ return [
$parent = $this->model();
}
if (is_a($parent, 'Kirby\Cms\File') === true) {
if ($parent instanceof File) {
$parent = $parent->parent();
}
@ -62,7 +62,7 @@ return [
'filename' => $filename,
]);
if (is_a($file, 'Kirby\Cms\File') === false) {
if ($file instanceof File === false) {
throw new Exception('The file could not be uploaded');
}

View file

@ -1,5 +1,7 @@
<?php
use Kirby\Toolkit\Str;
return [
'extends' => 'tags',
'props' => [
@ -28,5 +30,18 @@ return [
'sort' => function (bool $sort = false) {
return $sort;
},
]
],
'methods' => [
'toValues' => function ($value) {
if (is_null($value) === true) {
return [];
}
if (is_array($value) === false) {
$value = Str::split($value, $this->separator());
}
return $this->sanitizeOptions($value);
}
],
];

View file

@ -0,0 +1,104 @@
<?php
use Kirby\Data\Data;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Form\Form;
use Kirby\Toolkit\I18n;
return [
'props' => [
/**
* Unset inherited props
*/
'after' => null,
'before' => null,
'autofocus' => null,
'icon' => null,
'placeholder' => null,
/**
* Set the default values for the object
*/
'default' => function ($default = null) {
return $default;
},
/**
* The placeholder text if no information has been added yet
*/
'empty' => function ($empty = null) {
return I18n::translate($empty, $empty);
},
/**
* Fields setup for the object form. Works just like fields in regular forms.
*/
'fields' => function (array $fields = []) {
return $fields;
}
],
'computed' => [
'default' => function () {
if (empty($this->default) === true) {
return '';
}
return $this->form($this->default)->values();
},
'fields' => function () {
if (empty($this->fields) === true) {
throw new Exception('Please provide some fields for the object');
}
return $this->form()->fields()->toArray();
},
'value' => function () {
$data = Data::decode($this->value, 'yaml');
if (empty($data) === true) {
return '';
}
return $this->form($data)->values();
}
],
'methods' => [
'form' => function (array $values = []) {
return new Form([
'fields' => $this->attrs['fields'],
'values' => $values,
'model' => $this->model
]);
},
],
'save' => function ($value) {
if (empty($value) === true) {
return '';
}
return $this->form($value)->content();
},
'validations' => [
'object' => function ($value) {
if (empty($value) === true) {
return true;
}
$errors = $this->form($value)->errors();
if (empty($errors) === false) {
// use the first error for details
$name = array_key_first($errors);
$error = $errors[$name];
throw new InvalidArgumentException([
'key' => 'object.validation',
'data' => [
'label' => $error['label'] ?? $name,
'message' => implode("\n", $error['message'])
]
]);
}
}
]
];

View file

@ -67,7 +67,7 @@ return [
foreach (Data::decode($value, 'yaml') as $id) {
if (is_array($id) === true) {
$id = $id['id'] ?? null;
$id = $id['uuid'] ?? $id['id'] ?? null;
}
if ($id !== null && ($page = $kirby->page($id))) {
@ -102,7 +102,7 @@ return [
];
},
'save' => function ($value = null) {
return A::pluck($value, 'id');
return A::pluck($value, $this->store);
},
'validations' => [
'max',

View file

@ -108,7 +108,7 @@ return [
$columns = [];
$mobile = 0;
if (empty($this->columns)) {
if (empty($this->columns) === true) {
foreach ($this->fields as $field) {
// Skip hidden and unsaveable fields
// They should never be included as column
@ -129,7 +129,10 @@ return [
$field = $this->fields[$columnName] ?? null;
if (empty($field) === true || $field['saveable'] === false) {
if (
empty($field) === true ||
$field['saveable'] === false
) {
continue;
}
@ -137,10 +140,10 @@ return [
$mobile++;
}
$columns[$columnName] = array_merge($columnProps, [
$columns[$columnName] = array_merge([
'type' => $field['type'],
'label' => $field['label'] ?? $field['name']
]);
], $columnProps);
}
}

View file

@ -31,7 +31,7 @@ return [
* Set to `list` to display each tag with 100% width,
* otherwise the tags are displayed inline
*/
'layout' => function (?string $layout = null) {
'layout' => function (string|null $layout = null) {
return $layout;
},
/**
@ -55,43 +55,32 @@ return [
],
'computed' => [
'default' => function (): array {
return $this->toTags($this->default);
return $this->toValues($this->default);
},
'value' => function (): array {
return $this->toTags($this->value);
return $this->toValues($this->value);
}
],
'methods' => [
'toTags' => function ($value) {
'toValues' => function ($value) {
if (is_null($value) === true) {
return [];
}
$options = $this->options();
if (is_array($value) === false) {
$value = Str::split($value, $this->separator());
}
// transform into value-text objects
return array_map(function ($option) use ($options) {
// already a valid object
if (is_array($option) === true && isset($option['value'], $option['text']) === true) {
return $option;
}
if ($this->accept === 'options') {
$value = $this->sanitizeOptions($value);
}
$index = array_search($option, array_column($options, 'value'));
if ($index !== false) {
return $options[$index];
}
return [
'value' => $option,
'text' => $option,
];
}, Str::split($value, $this->separator()));
return $value;
}
],
'save' => function (array $value = null): string {
return A::join(
A::pluck($value, 'value'),
$value,
$this->separator() . ' '
);
},

View file

@ -15,7 +15,7 @@ return [
/**
* Sets the default time when a new page/file/user is created
*/
'default' => function ($default = null): ?string {
'default' => function ($default = null): string|null {
return $default;
},
@ -36,13 +36,13 @@ return [
/**
* Latest time, which can be selected/saved (H:i or H:i:s)
*/
'max' => function (string $max = null): ?string {
'max' => function (string $max = null): string|null {
return Date::optional($max);
},
/**
* Earliest time, which can be selected/saved (H:i or H:i:s)
*/
'min' => function (string $min = null): ?string {
'min' => function (string $min = null): string|null {
return Date::optional($min);
},
@ -62,7 +62,7 @@ return [
'unit' => 'minute',
]);
},
'value' => function ($value = null): ?string {
'value' => function ($value = null): string|null {
return $value;
}
],
@ -80,7 +80,7 @@ return [
'format' => function () {
return $this->props['format'] ?? 'H:i:s';
},
'value' => function (): ?string {
'value' => function (): string|null {
return $this->toDatetime($this->value, 'H:i:s') ?? '';
}
],

View file

@ -49,9 +49,9 @@ return [
'value' => function () {
if ($this->props['value'] === null) {
return $this->default();
} else {
return $this->toBool($this->props['value']);
}
return $this->toBool($this->props['value']);
}
],
'methods' => [

View file

@ -96,7 +96,7 @@ return [
];
},
'save' => function ($value = null) {
return A::pluck($value, 'id');
return A::pluck($value, $this->store);
},
'validations' => [
'max',

View file

@ -3,10 +3,10 @@
use Kirby\Cms\App;
use Kirby\Cms\Helpers;
use Kirby\Cms\Html;
use Kirby\Cms\Response;
use Kirby\Cms\Url;
use Kirby\Filesystem\Asset;
use Kirby\Filesystem\F;
use Kirby\Http\Response;
use Kirby\Http\Router;
use Kirby\Toolkit\Date;
use Kirby\Toolkit\I18n;
@ -35,7 +35,7 @@ if (Helpers::hasOverride('attr') === false) { // @codeCoverageIgnore
* @param string|null $after An optional string that will be appended if the result is not empty
* @return string|null
*/
function attr(?array $attr = null, ?string $before = null, ?string $after = null): ?string
function attr(array|null $attr = null, string|null $before = null, string|null $after = null): string|null
{
return Html::attr($attr, null, $before, $after);
}
@ -61,7 +61,7 @@ if (Helpers::hasOverride('csrf') === false) { // @codeCoverageIgnore
* @param string|null $check Pass a token here to compare it to the one in the session
* @return string|bool Either the token or a boolean check result
*/
function csrf(?string $check = null)
function csrf(string|null $check = null)
{
// check explicitly if there have been no arguments at all;
// checking for null introduces a security issue because null could come
@ -82,7 +82,7 @@ if (Helpers::hasOverride('css') === false) { // @codeCoverageIgnore
* @param string|array $options Pass an array of attributes for the link tag or a media attribute string
* @return string|null
*/
function css($url, $options = null): ?string
function css($url, $options = null): string|null
{
return Html::css($url, $options);
}
@ -167,7 +167,7 @@ if (Helpers::hasOverride('gist') === false) { // @codeCoverageIgnore
* @param string|null $file
* @return string
*/
function gist(string $url, ?string $file = null): string
function gist(string $url, string|null $file = null): string
{
return App::instance()->kirbytag([
'gist' => $url,
@ -199,7 +199,7 @@ if (Helpers::hasOverride('h') === false) { // @codeCoverageIgnore
* @param bool $keepTags
* @return string
*/
function h(?string $string, bool $keepTags = false): string
function h(string|null $string, bool $keepTags = false): string
{
return Html::encode($string, $keepTags);
}
@ -213,7 +213,7 @@ if (Helpers::hasOverride('html') === false) { // @codeCoverageIgnore
* @param bool $keepTags
* @return string
*/
function html(?string $string, bool $keepTags = false): string
function html(string|null $string, bool $keepTags = false): string
{
return Html::encode($string, $keepTags);
}
@ -230,7 +230,7 @@ if (Helpers::hasOverride('image') === false) { // @codeCoverageIgnore
* @param string|null $path
* @return \Kirby\Cms\File|null
*/
function image(?string $path = null)
function image(string|null $path = null)
{
return App::instance()->image($path);
}
@ -259,7 +259,7 @@ if (Helpers::hasOverride('js') === false) { // @codeCoverageIgnore
* @param string|array $options
* @return string|null
*/
function js($url, $options = null): ?string
function js($url, $options = null): string|null
{
return Html::js($url, $options);
}
@ -287,7 +287,7 @@ if (Helpers::hasOverride('kirbytag') === false) { // @codeCoverageIgnore
* @param array $data
* @return string
*/
function kirbytag($type, ?string $value = null, array $attr = [], array $data = []): string
function kirbytag($type, string|null $value = null, array $attr = [], array $data = []): string
{
return App::instance()->kirbytag($type, $value, $attr, $data);
}
@ -302,7 +302,7 @@ if (Helpers::hasOverride('kirbytags') === false) { // @codeCoverageIgnore
* @param array $data
* @return string
*/
function kirbytags(?string $text = null, array $data = []): string
function kirbytags(string|null $text = null, array $data = []): string
{
return App::instance()->kirbytags($text, $data);
}
@ -317,7 +317,7 @@ if (Helpers::hasOverride('kirbytext') === false) { // @codeCoverageIgnore
* @param array $data
* @return string
*/
function kirbytext(?string $text = null, array $data = []): string
function kirbytext(string|null $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data);
}
@ -333,7 +333,7 @@ if (Helpers::hasOverride('kirbytextinline') === false) { // @codeCoverageIgnore
* @param array $options
* @return string
*/
function kirbytextinline(?string $text = null, array $options = []): string
function kirbytextinline(string|null $text = null, array $options = []): string
{
$options['markdown']['inline'] = true;
return App::instance()->kirbytext($text, $options);
@ -348,7 +348,7 @@ if (Helpers::hasOverride('kt') === false) { // @codeCoverageIgnore
* @param array $data
* @return string
*/
function kt(?string $text = null, array $data = []): string
function kt(string|null $text = null, array $data = []): string
{
return App::instance()->kirbytext($text, $data);
}
@ -363,7 +363,7 @@ if (Helpers::hasOverride('kti') === false) { // @codeCoverageIgnore
* @param array $options
* @return string
*/
function kti(?string $text = null, array $options = []): string
function kti(string|null $text = null, array $options = []): string
{
$options['markdown']['inline'] = true;
return App::instance()->kirbytext($text, $options);
@ -378,7 +378,7 @@ if (Helpers::hasOverride('load') === false) { // @codeCoverageIgnore
* @param string|null $base
* @return void
*/
function load(array $classmap, ?string $base = null): void
function load(array $classmap, string|null $base = null): void
{
F::loadClasses($classmap, $base);
}
@ -393,7 +393,7 @@ if (Helpers::hasOverride('markdown') === false) { // @codeCoverageIgnore
* @param array $options
* @return string
*/
function markdown(?string $text = null, array $options = []): string
function markdown(string|null $text = null, array $options = []): string
{
return App::instance()->markdown($text, $options);
}
@ -421,7 +421,7 @@ if (Helpers::hasOverride('page') === false) { // @codeCoverageIgnore
* @param string|null $id
* @return \Kirby\Cms\Page|null
*/
function page(?string $id = null)
function page(string|null $id = null)
{
if (empty($id) === true) {
return App::instance()->site()->page();
@ -459,8 +459,9 @@ if (Helpers::hasOverride('param') === false) { // @codeCoverageIgnore
* @param string $key
* @param string|null $fallback
* @return string|null
* @psalm-return ($fallback is string ? string : string|null)
*/
function param(string $key, ?string $fallback = null): ?string
function param(string $key, string|null $fallback = null): string|null
{
return App::instance()->request()->url()->params()->$key ?? $fallback;
}
@ -505,7 +506,7 @@ if (Helpers::hasOverride('router') === false) { // @codeCoverageIgnore
* @param \Closure|null $callback
* @return mixed
*/
function router(?string $path = null, string $method = 'GET', array $routes = [], ?Closure $callback = null)
function router(string|null $path = null, string $method = 'GET', array $routes = [], Closure|null $callback = null)
{
return Router::execute($path, $method, $routes, $callback);
}
@ -545,7 +546,7 @@ if (Helpers::hasOverride('smartypants') === false) { // @codeCoverageIgnore
* @param string|null $text
* @return string
*/
function smartypants(?string $text = null): string
function smartypants(string|null $text = null): string
{
return App::instance()->smartypants($text);
}
@ -560,7 +561,7 @@ if (Helpers::hasOverride('snippet') === false) { // @codeCoverageIgnore
* @param bool $return
* @return string|null
*/
function snippet($name, $data = [], bool $return = false): ?string
function snippet($name, $data = [], bool $return = false): string|null
{
return App::instance()->snippet($name, $data, $return);
}
@ -624,7 +625,7 @@ if (Helpers::hasOverride('timestamp') === false) { // @codeCoverageIgnore
* @param int|array|null $step array of `unit` and `size` to round to nearest
* @return int|null
*/
function timestamp(?string $date = null, $step = null): ?int
function timestamp(string|null $date = null, $step = null): int|null
{
return Date::roundedTimestamp($date, $step);
}
@ -641,7 +642,7 @@ if (Helpers::hasOverride('tt') === false) { // @codeCoverageIgnore
* @param string|null $locale
* @return string
*/
function tt(string $key, $fallback = null, ?array $replace = null, ?string $locale = null): string
function tt(string $key, $fallback = null, array|null $replace = null, string|null $locale = null): string
{
return I18n::template($key, $fallback, $replace, $locale);
}
@ -657,7 +658,7 @@ if (Helpers::hasOverride('twitter') === false) { // @codeCoverageIgnore
* @param string|null $class
* @return string
*/
function twitter(string $username, ?string $text = null, ?string $title = null, ?string $class = null): string
function twitter(string $username, string|null $text = null, string|null $title = null, string|null $class = null): string
{
return App::instance()->kirbytag([
'twitter' => $username,
@ -676,7 +677,7 @@ if (Helpers::hasOverride('u') === false) { // @codeCoverageIgnore
* @param array|string|null $options
* @return string
*/
function u(?string $path = null, $options = null): string
function u(string|null $path = null, $options = null): string
{
return Url::to($path, $options);
}
@ -690,7 +691,7 @@ if (Helpers::hasOverride('url') === false) { // @codeCoverageIgnore
* @param array|string|null $options
* @return string
*/
function url(?string $path = null, $options = null): string
function url(string|null $path = null, $options = null): string
{
return Url::to($path, $options);
}
@ -719,7 +720,7 @@ if (Helpers::hasOverride('video') === false) { // @codeCoverageIgnore
* @param array $attr
* @return string|null
*/
function video(string $url, array $options = [], array $attr = []): ?string
function video(string $url, array $options = [], array $attr = []): string|null
{
return Html::video($url, $options, $attr);
}
@ -734,7 +735,7 @@ if (Helpers::hasOverride('vimeo') === false) { // @codeCoverageIgnore
* @param array $attr
* @return string|null
*/
function vimeo(string $url, array $options = [], array $attr = []): ?string
function vimeo(string $url, array $options = [], array $attr = []): string|null
{
return Html::vimeo($url, $options, $attr);
}
@ -764,7 +765,7 @@ if (Helpers::hasOverride('youtube') === false) { // @codeCoverageIgnore
* @param array $attr
* @return string|null
*/
function youtube(string $url, array $options = [], array $attr = []): ?string
function youtube(string $url, array $options = [], array $attr = []): string|null
{
return Html::youtube($url, $options, $attr);
}

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);
@ -341,7 +350,7 @@ return function (App $app) {
* @param string $context Location of output (`html`, `attr`, `js`, `css`, `url` or `xml`)
*/
'escape' => function (Field $field, string $context = 'html') {
$field->value = Str::esc($field->value, $context);
$field->value = Str::esc($field->value ?? '', $context);
return $field;
},
@ -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);

View file

@ -5,7 +5,7 @@ use Kirby\Toolkit\I18n;
return function (array $props) {
$props['sections'] = [
'files' => [
'headline' => $props['headline'] ?? I18n::translate('files'),
'label' => $props['label'] ?? $props['headline'] ?? I18n::translate('files'),
'type' => 'files',
'layout' => $props['layout'] ?? 'cards',
'template' => $props['template'] ?? null,
@ -17,6 +17,7 @@ return function (array $props) {
// remove global options
unset(
$props['headline'],
$props['label'],
$props['layout'],
$props['template'],
$props['image']

View file

@ -10,7 +10,7 @@ return function ($props) {
if (is_string($props) === true) {
$props = [
'headline' => $props
'label' => $props
];
}
@ -27,18 +27,18 @@ return function ($props) {
if ($pages !== false) {
$sidebar['pages'] = $section([
'headline' => I18n::translate('pages'),
'type' => 'pages',
'status' => 'all',
'layout' => 'list',
'label' => I18n::translate('pages'),
'type' => 'pages',
'status' => 'all',
'layout' => 'list',
], $pages);
}
if ($files !== false) {
$sidebar['files'] = $section([
'headline' => I18n::translate('files'),
'type' => 'files',
'layout' => 'list'
'label' => I18n::translate('files'),
'type' => 'files',
'layout' => 'list'
], $files);
}
}

View file

@ -6,12 +6,12 @@ return function (array $props) {
// load the general templates setting for all sections
$templates = $props['templates'] ?? null;
$section = function ($headline, $status, $props) use ($templates) {
$section = function ($label, $status, $props) use ($templates) {
$defaults = [
'headline' => $headline,
'type' => 'pages',
'layout' => 'list',
'status' => $status
'label' => $label,
'type' => 'pages',
'layout' => 'list',
'status' => $status
];
if ($props === true) {
@ -20,7 +20,7 @@ return function (array $props) {
if (is_string($props) === true) {
$props = [
'headline' => $props
'label' => $props
];
}

View file

@ -6,6 +6,7 @@ use Kirby\Cms\PluginAssets;
use Kirby\Panel\Panel;
use Kirby\Panel\Plugins;
use Kirby\Toolkit\Str;
use Kirby\Uuid\Uuid;
return function ($kirby) {
$api = $kirby->option('api.slug', 'api');
@ -101,6 +102,26 @@ return function ($kirby) {
return Panel::router($path);
}
],
// permalinks for page/file UUIDs
[
'pattern' => '@/(page|file)/(:all)',
'method' => 'ALL',
'env' => 'site',
'action' => function (string $type, string $id) use ($kirby) {
// try to resolve to model, but only from UUID cache;
// this ensures that only existing UUIDs can be queried
// and attackers can't force Kirby to go through the whole
// site index with a non-existing UUID
if ($model = Uuid::for($type . '://' . $id)?->model(true)) {
return $kirby
->response()
->redirect($model->url());
}
// render the error page
return false;
}
],
];
// Multi-language setup

View file

@ -1,5 +1,7 @@
<?php
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Form\Form;
return [
@ -31,7 +33,10 @@ return [
'fields' => function () {
$fields = $this->form->fields()->toArray();
if (is_a($this->model, 'Kirby\Cms\Page') === true || is_a($this->model, 'Kirby\Cms\Site') === true) {
if (
$this->model instanceof Page ||
$this->model instanceof Site
) {
// the title should never be updated directly via
// fields section to avoid conflicts with the rename dialog
unset($fields['title']);

View file

@ -25,9 +25,9 @@ return [
],
'toArray' => function () {
return [
'headline' => $this->headline,
'text' => $this->text,
'theme' => $this->theme
'label' => $this->headline,
'text' => $this->text,
'theme' => $this->theme
];
}
];

View file

@ -1,20 +1,14 @@
<?php
use Kirby\Cms\Helpers;
use Kirby\Toolkit\I18n;
return [
'props' => [
/**
* The headline for the section. This can be a simple string or a template with additional info from the parent page.
* @todo remove in 3.9.0
* @deprecated 3.8.0 Use `label` instead
*/
'headline' => function ($headline = null) {
// TODO: add deprecation notive in 3.8.0
// if ($headline !== null) {
// Helpers::deprecated('`headline` prop for sections has been deprecated and will be removed in Kirby 3.9.0. Use `label` instead.');
// }
return I18n::translate($headline, $headline);
},
/**
@ -28,14 +22,14 @@ return [
],
'computed' => [
'headline' => function () {
if ($this->headline) {
return $this->model()->toString($this->headline);
}
if ($this->label) {
return $this->model()->toString($this->label);
}
if ($this->headline) {
return $this->model()->toString($this->headline);
}
return ucfirst($this->name);
}
]

View file

@ -1,5 +1,9 @@
<?php
use Kirby\Cms\File;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Cms\User;
use Kirby\Exception\Exception;
return [
@ -24,10 +28,10 @@ return [
}
if (
is_a($parent, 'Kirby\Cms\Page') === false &&
is_a($parent, 'Kirby\Cms\Site') === false &&
is_a($parent, 'Kirby\Cms\File') === false &&
is_a($parent, 'Kirby\Cms\User') === false
$parent instanceof Page === false &&
$parent instanceof Site === false &&
$parent instanceof File === false &&
$parent instanceof User === false
) {
throw new Exception('The parent for the section "' . $this->name() . '" has to be a page, site or user object');
}

View file

@ -12,7 +12,7 @@ return [
}
],
'methods' => [
'searchterm' => function (): ?string {
'searchterm' => function (): string|null {
return App::instance()->request()->get('searchterm');
}
]

View file

@ -1,6 +1,8 @@
<?php
use Kirby\Cms\Blueprint;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\I18n;
@ -53,8 +55,8 @@ return [
$parent = $this->parentModel();
if (
is_a($parent, 'Kirby\Cms\Site') === false &&
is_a($parent, 'Kirby\Cms\Page') === false
$parent instanceof Site === false &&
$parent instanceof Page === false
) {
throw new InvalidArgumentException('The parent is invalid. You must choose the site or a page as parent.');
}
@ -62,22 +64,13 @@ return [
return $parent;
},
'pages' => function () {
switch ($this->status) {
case 'draft':
$pages = $this->parent->drafts();
break;
case 'listed':
$pages = $this->parent->children()->listed();
break;
case 'published':
$pages = $this->parent->children();
break;
case 'unlisted':
$pages = $this->parent->children()->unlisted();
break;
default:
$pages = $this->parent->childrenAndDrafts();
}
$pages = match ($this->status) {
'draft' => $this->parent->drafts(),
'listed' => $this->parent->children()->listed(),
'published' => $this->parent->children(),
'unlisted' => $this->parent->children()->unlisted(),
default => $this->parent->childrenAndDrafts()
};
// filters pages that are protected and not in the templates list
// internal `filter()` method used instead of foreach loop that previously included `unset()`
@ -228,7 +221,7 @@ return [
'name' => basename($props['name']),
'title' => $props['title'],
];
} catch (Throwable $e) {
} catch (Throwable) {
$blueprints[] = [
'name' => basename($template),
'title' => ucfirst($template),

View file

@ -47,10 +47,12 @@ return [
continue;
}
$info = $report['info'] ?? null;
$reports[] = [
'label' => I18n::translate($report['label'], $report['label']),
'value' => $value($report['value'] ?? null),
'info' => $value($report['info'] ?? null),
'info' => $value(I18n::translate($info, $info)),
'link' => $value($report['link'] ?? null),
'theme' => $value($report['theme'] ?? null)
];

View file

@ -2,6 +2,7 @@
/**
* Constants
* @deprecated 3.8.0 Use `/` instead
*/
define('DS', '/');

View file

@ -3,6 +3,7 @@
use Kirby\Cms\Html;
use Kirby\Cms\Url;
use Kirby\Toolkit\Str;
use Kirby\Uuid\Uuid;
/**
* Default KirbyTags definition
@ -117,11 +118,8 @@ return [
return $img;
}
if ($link = $tag->file($tag->link)) {
$link = $link->url();
} else {
$link = $tag->link === 'self' ? $tag->src : $tag->link;
}
$link = $tag->file($tag->link)?->url();
$link ??= $tag->link === 'self' ? $tag->src : $tag->link;
return Html::a($link, [$img], [
'rel' => $tag->rel,
@ -173,6 +171,15 @@ return [
$tag->value = Url::to($tag->value, $tag->lang);
}
// if value is a UUID, resolve to page/file model
// and use the URL as value
if (
Uuid::is($tag->value, 'page') === true ||
Uuid::is($tag->value, 'file') === true
) {
$tag->value = Uuid::for($tag->value)->model()->url();
}
return Html::a($tag->value, $tag->text, [
'rel' => $tag->rel,
'class' => $tag->class,