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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class PageCreateDialog
|
|||
'tags',
|
||||
'tel',
|
||||
'text',
|
||||
'toggle',
|
||||
'toggles',
|
||||
'time',
|
||||
'url'
|
||||
|
|
@ -247,8 +248,9 @@ class PageCreateDialog
|
|||
*/
|
||||
public function model(): Page
|
||||
{
|
||||
// TODO: use actual in-memory page in v5
|
||||
return $this->model ??= Page::factory([
|
||||
'slug' => 'new',
|
||||
'slug' => '__new__',
|
||||
'template' => $this->template,
|
||||
'model' => $this->template,
|
||||
'parent' => $this->parent instanceof Page ? $this->parent : null
|
||||
|
|
@ -266,12 +268,7 @@ class PageCreateDialog
|
|||
|
||||
// create temporary page object
|
||||
// to resolve the template strings
|
||||
$page = new Page([
|
||||
'slug' => 'tmp',
|
||||
'template' => $this->template,
|
||||
'parent' => $this->model(),
|
||||
'content' => $input
|
||||
]);
|
||||
$page = $this->model()->clone(['content' => $input]);
|
||||
|
||||
if (is_string($title)) {
|
||||
$input['title'] = $page->toSafeString($title);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class User extends Model
|
|||
'dialog' => $url . '/changeRole',
|
||||
'icon' => 'bolt',
|
||||
'text' => I18n::translate('user.changeRole'),
|
||||
'disabled' => $this->isDisabledDropdownOption('changeRole', $options, $permissions)
|
||||
'disabled' => $this->isDisabledDropdownOption('changeRole', $options, $permissions) || $this->model->roles()->count() < 2
|
||||
];
|
||||
|
||||
$result[] = [
|
||||
|
|
@ -218,14 +218,19 @@ class User extends Model
|
|||
*/
|
||||
public function props(): array
|
||||
{
|
||||
$user = $this->model;
|
||||
$account = $user->isLoggedIn();
|
||||
$user = $this->model;
|
||||
$account = $user->isLoggedIn();
|
||||
$permissions = $this->options();
|
||||
|
||||
return array_merge(
|
||||
parent::props(),
|
||||
$account ? [] : $this->prevNext(),
|
||||
$this->prevNext(),
|
||||
[
|
||||
'blueprint' => $this->model->role()->name(),
|
||||
'blueprint' => $this->model->role()->name(),
|
||||
'canChangeEmail' => $permissions['changeEmail'],
|
||||
'canChangeLanguage' => $permissions['changeLanguage'],
|
||||
'canChangeName' => $permissions['changeName'],
|
||||
'canChangeRole' => $this->model->roles()->count() > 1,
|
||||
'model' => [
|
||||
'account' => $account,
|
||||
'avatar' => $user->avatar()?->url(),
|
||||
|
|
|
|||
|
|
@ -275,6 +275,9 @@ class View
|
|||
|
||||
return [
|
||||
'$config' => fn () => [
|
||||
'api' => [
|
||||
'methodOverwrite' => $kirby->option('api.methodOverwrite', true)
|
||||
],
|
||||
'debug' => $kirby->option('debug', false),
|
||||
'kirbytext' => $kirby->option('panel.kirbytext', true),
|
||||
'translation' => $kirby->option('panel.language', 'en'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue