bruno
1
does anybody know how to get a reference to the $page
object from where i’m opening a new customised (kirby 3.6) panel dialog?
trying like this:
'submit' => function ($id) {
$page = page($id);
$archive = page('archive');
$page->copy(['parent' => $archive]);
return true;
}
but seems like $id
is never passed to the submit function:
Error: Too few arguments to function Kirby\Http\Route::{closure}(), 0 passed and exactly 1 expected
does this only work when extending dialogs? (Panel dialogs | Kirby CMS)
bruno
2
Got it! Wasn’t sure about the interplay of dropdown
and dialog
, but this works now:
plugins/amazingplugin/index.php
'page' => function (string $id) {
// find the right page for the dropdown
$page = Find::page($id);
// load the core dropdown definition
$dropdown = $page->panel()->dropdown();
if ($page->intendedTemplate() == 'programm-element') {
// append a separator
// $dropdown[] = '-';
// append a new option
$dropdown[] = [
'icon' => 'folder',
'text' => 'Archivieren',
'dialog' => 'archive/' . $id,
];
}
return $dropdown;
}
],
'dialogs' => [
'archive/(:any)' => require __DIR__ . '/dialogs/page.archive.php',
],
plugins/amazingplugin/dialogs/page.archive.php
<?php
return [
'load' => function (string $id) {
$page = Find::page($id);
return [
'component' => 'k-text-dialog',
'props' => [
'text' => 'Willst du die Seite ' . $page->title() . ' ins Archiv verschieben?',
'theme' => 'success',
'submitButton' => 'Archivieren',
'icon' => 'folder',
],
];
},
'submit' => function (string $id) {
$page = Find::page($id);
$archive = Find::page('archiv');
$page->copy(['parent' => $archive]);
// have to write some nice try/catch blocks to handle page duplication and deletion etc
return true;
}
];