Skip to content

Refactor dialogs + drawers as classes #6967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: v6/develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions config/areas/account/dialogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@
'pattern' => '(account)/files/(:any)/fields/(:any)/(:all?)',
],
'account.totp.enable' => [
'pattern' => '(account)/totp/enable',
'load' => fn () => (new UserTotpEnableDialog())->load(),
'submit' => fn () => (new UserTotpEnableDialog())->submit()
'pattern' => '(account)/totp/enable',
'controller' => UserTotpEnableDialog::class
],
'account.totp.disable' => [
'pattern' => '(account)/totp/disable',
...$dialogs['user.totp.disable'],
'pattern' => '(account)/totp/disable',
],
];
61 changes: 0 additions & 61 deletions config/areas/fields/dialogs.php

This file was deleted.

61 changes: 0 additions & 61 deletions config/areas/fields/drawers.php

This file was deleted.

155 changes: 9 additions & 146 deletions config/areas/files/dialogs.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

use Kirby\Cms\Find;
use Kirby\Panel\Field;
use Kirby\Panel\Panel;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\I18n;
use Kirby\Panel\Ui\Dialogs\FileChangeNameDialog;
use Kirby\Panel\Ui\Dialogs\FileChangeSortDialog;
use Kirby\Panel\Ui\Dialogs\FileChangeTemplateDialog;
use Kirby\Panel\Ui\Dialogs\FileDeleteDialog;

/**
* Shared file dialogs
Expand All @@ -15,151 +14,15 @@
*/
return [
'changeName' => [
'load' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
return [
'component' => 'k-form-dialog',
'props' => [
'fields' => [
'name' => [
'label' => I18n::translate('name'),
'type' => 'slug',
'required' => true,
'icon' => 'title',
'allow' => 'a-z0-9@._-',
'after' => '.' . $file->extension(),
'preselect' => true
]
],
'submitButton' => I18n::translate('rename'),
'value' => [
'name' => $file->name(),
]
]
];
},
'submit' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$name = $file->kirby()->request()->get('name');
$renamed = $file->changeName($name);
$oldUrl = $file->panel()->url(true);
$newUrl = $renamed->panel()->url(true);
$response = [
'event' => 'file.changeName'
];

// check for a necessary redirect after the filename has changed
if (Panel::referrer() === $oldUrl && $oldUrl !== $newUrl) {
$response['redirect'] = $newUrl;
}

return $response;
}
'controller' => FileChangeNameDialog::class
],

'changeSort' => [
'load' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
return [
'component' => 'k-form-dialog',
'props' => [
'fields' => [
'position' => Field::filePosition($file)
],
'submitButton' => I18n::translate('change'),
'value' => [
'position' => $file->sort()->isEmpty() ? $file->siblings(false)->count() + 1 : $file->sort()->toInt(),
]
]
];
},
'submit' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$files = $file->siblings()->sorted();
$ids = $files->keys();
$newIndex = (int)($file->kirby()->request()->get('position')) - 1;
$oldIndex = $files->indexOf($file);

array_splice($ids, $oldIndex, 1);
array_splice($ids, $newIndex, 0, $file->id());

$files->changeSort($ids);

return [
'event' => 'file.sort',
];
}
'controller' => FileChangeSortDialog::class
],

'changeTemplate' => [
'load' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$blueprints = $file->blueprints();

return [
'component' => 'k-form-dialog',
'props' => [
'fields' => [
'warning' => [
'type' => 'info',
'theme' => 'notice',
'text' => I18n::translate('file.changeTemplate.notice')
],
'template' => Field::template($blueprints, [
'required' => true
])
],
'theme' => 'notice',
'submitButton' => I18n::translate('change'),
'value' => [
'template' => $file->template()
]
]
];
},
'submit' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$template = $file->kirby()->request()->get('template');

$file->changeTemplate($template);

return [
'event' => 'file.changeTemplate',
];
}
'controller' => FileChangeTemplateDialog::class
],

'delete' => [
'load' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
return [
'component' => 'k-remove-dialog',
'props' => [
'text' => I18n::template('file.delete.confirm', [
'filename' => Escape::html($file->filename())
]),
]
];
},
'submit' => function (string $path, string $filename) {
$file = Find::file($path, $filename);
$redirect = false;
$referrer = Panel::referrer();
$url = $file->panel()->url(true);

$file->delete();

// redirect to the parent model URL
// if the dialog has been opened in the file view
if ($referrer === $url) {
$redirect = $file->parent()->panel()->url(true);
}

return [
'event' => 'file.delete',
'redirect' => $redirect
];
}
],

'controller' => FileDeleteDialog::class
]
];
27 changes: 3 additions & 24 deletions config/areas/lab/drawers.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
<?php

use Kirby\Panel\Lab\Doc;
use Kirby\Panel\Lab\Docs;
use Kirby\Panel\Ui\Drawers\LabsDocsDrawer;

return [
'lab.docs' => [
'pattern' => 'lab/docs/(:any)',
'load' => function (string $component) {
if (Docs::isInstalled() === false) {
return [
'component' => 'k-text-drawer',
'props' => [
'text' => 'The UI docs are not installed.'
]
];
}

$doc = Doc::factory($component);

return [
'component' => 'k-lab-docs-drawer',
'props' => [
'icon' => 'book',
'title' => $component,
'docs' => $doc->toArray()
]
];
},
'pattern' => 'lab/docs/(:any)',
'controller' => LabsDocsDrawer::class
],
];
Loading
Loading