Update to Kirby 4.7.0

This commit is contained in:
Paul Nicoué 2025-04-21 18:57:21 +02:00
parent 02a9ab387c
commit ba25a9a198
509 changed files with 26604 additions and 14872 deletions

View file

@ -4,8 +4,13 @@ namespace Kirby\Panel;
use Kirby\Cms\App;
use Kirby\Cms\File;
use Kirby\Cms\ModelWithContent;
use Kirby\Cms\Page;
use Kirby\Cms\Roles;
use Kirby\Form\Form;
use Kirby\Http\Router;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
/**
* Provides common field prop definitions
@ -20,6 +25,58 @@ use Kirby\Toolkit\I18n;
*/
class Field
{
/**
* Creates the routes for a field dialog
* This is most definitely not a good place for this
* method, but as long as the other classes are
* not fully refactored, it still feels appropriate
*/
public static function dialog(
ModelWithContent $model,
string $fieldName,
string|null $path = null,
string $method = 'GET',
) {
$field = Form::for($model)->field($fieldName);
$routes = [];
foreach ($field->dialogs() as $dialogId => $dialog) {
$routes = array_merge($routes, Dialog::routes(
id: $dialogId,
areaId: 'site',
options: $dialog
));
}
return Router::execute($path, $method, $routes);
}
/**
* Creates the routes for a field drawer
* This is most definitely not a good place for this
* method, but as long as the other classes are
* not fully refactored, it still feels appropriate
*/
public static function drawer(
ModelWithContent $model,
string $fieldName,
string|null $path = null,
string $method = 'GET',
) {
$field = Form::for($model)->field($fieldName);
$routes = [];
foreach ($field->drawers() as $drawerId => $drawer) {
$routes = array_merge($routes, Drawer::routes(
id: $drawerId,
areaId: 'site',
options: $drawer
));
}
return Router::execute($path, $method, $routes);
}
/**
* A standard email field
*/
@ -73,7 +130,7 @@ class Field
public static function hidden(): array
{
return ['type' => 'hidden'];
return ['hidden' => true];
}
/**
@ -135,30 +192,33 @@ class Field
/**
* User role radio buttons
*/
public static function role(array $props = []): array
{
$kirby = App::instance();
$user = $kirby->user();
$isAdmin = $user && $user->isAdmin();
$roles = [];
public static function role(
array $props = [],
Roles|null $roles = null
): array {
$kirby = App::instance();
foreach ($kirby->roles() as $role) {
// exclude the admin role, if the user
// is not allowed to change role to admin
if ($role->name() === 'admin' && $isAdmin === false) {
continue;
}
// if no $roles where provided, fall back to all roles
$roles ??= $kirby->roles();
$roles[] = [
'text' => $role->title(),
'info' => $role->description() ?? I18n::translate('role.description.placeholder'),
'value' => $role->name()
];
}
// exclude the admin role, if the user
// is not allowed to change role to admin
$roles = $roles->filter(
fn ($role) =>
$role->name() !== 'admin' ||
$kirby->user()?->isAdmin() === true
);
// turn roles into radio field options
$roles = $roles->values(fn ($role) => [
'text' => $role->title(),
'info' => $role->description() ?? I18n::translate('role.description.placeholder'),
'value' => $role->name()
]);
return array_merge([
'label' => I18n::translate('role'),
'type' => count($roles) <= 1 ? 'hidden' : 'radio',
'type' => count($roles) < 1 ? 'hidden' : 'radio',
'options' => $roles
], $props);
}
@ -168,11 +228,14 @@ class Field
return array_merge([
'label' => I18n::translate('slug'),
'type' => 'slug',
'allow' => Str::$defaults['slug']['allowed']
], $props);
}
public static function template(array|null $blueprints = [], array|null $props = []): array
{
public static function template(
array|null $blueprints = [],
array|null $props = []
): array {
$options = [];
foreach ($blueprints as $blueprint) {
@ -217,7 +280,7 @@ class Field
return array_merge([
'label' => I18n::translate('language'),
'type' => 'select',
'icon' => 'globe',
'icon' => 'translate',
'options' => $translations,
'empty' => false
], $props);