Reuse panel core delete dialog

hi everyone,

i try to delete a file by my own plugin and i’ve found a snippet in this kirby documentation, to change the page status.

return $kirby->core()->area('site')['dialogs']['page.changeStatus']['load']($id);

The code above works fine but if i try the same code and change the dialog name to page.file.delete i will get an error -.-

That’s my code…

return [
    'pattern' => 'filebrowser/(:any)/delete',
    'load' => function ( string $filename )  {
        return kirby()->core()->area('site')['dialogs']['page.file.delete']['load']($filename);

This is the error:

Too few arguments to function Kirby\Cms\Loader::{closure}(), 1 passed in […]filebrowser/dialogs/delete.php on line 6 and exactly 2 expected

I can’t find any documentation for the dialogs anywhere :confused:

Can anyone explain me how i can use the delete dialog?

The documentation is here: Panel dialogs | Kirby CMS

I’m missing a bit of context in your code snippet, what are you trying to do?

Yes, this part of documentation i’ve found. I develop a plugin to manage uploaded files, so the user can delete, rename, replace files. I know the file section can do this but we want a little bit more. Now i try to delete a file - doing this with a dropdown and call the route /filebrwoser/(:any)/delete. This triggers my action (code from the first post). I thought I could use the core code, so I don’t have to program the delete and dialog logic by myself but it didn’t work.

Those dialogs are part of areas, but you don’t seem to be in an area context? Rather looks like a route?

Yes this is a route from the options…

From the docs, I don’t think that’s possible, because you are trying to reuse something from the site area outside the site area. At least this reuse of Panel core code is only mentioned in the context of extending the site area.

OK. What is the solution? Build the dialogs for deleting and renaming yourself and also the logic? Is there no other way to delete and rename a file? This functions are available in the core, so i thought i could use them. The dialog page.changeStatus, which i built in for testing, worked perfectly, but none of the others did.

In the same context?

Yes in my own plugin

Maybe if you use the same dialog route, it works. But I’m not deeply enough into this yet without testing it first.

Ping @distantnative: Is this possible?

oh of course! I’ve found the panel core routes in some files…


mediastore is my folder which stores all uplaoded files.

    'text'   => t( [
        'en' => 'Delete',
        'de' => 'Löschen'
    ] ),
    'icon'   => 'trash',
    'dialog' => 'pages/mediastore/files/'.$file.'/delete'

This works fine! But it feels wrong :sweat_smile:

I am a bit lost in the conversation, didn’t really get what is the actual aim here.

But looking at

return kirby()->core()->area('site')['dialogs']['page.file.delete']['load']($filename);

the main problem is that you are trying to call that load function of page.file.delete with only one parameter, while it expects two parameters: first the path where that file in your content structure is located and only second the filename.