fix #72 - update to Kirby 4.5
This commit is contained in:
parent
cb1f842fc9
commit
44d08b3e21
273 changed files with 678 additions and 54176 deletions
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
|
@ -191,29 +192,33 @@ class Field
|
|||
/**
|
||||
* User role radio buttons
|
||||
*/
|
||||
public static function role(array $props = []): array
|
||||
{
|
||||
$kirby = App::instance();
|
||||
$isAdmin = $kirby->user()?->isAdmin() ?? false;
|
||||
$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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue