Skip to content

Kirby 6.0.0

Panel dropdowns

The Panel loads dropdowns on request. This way, Kirby can evaluate permissions on the backend and disable the options that the current user can't use.

As part of your Panel area extension, you can define your own dropdowns on the backend and use them in your Panel components with a single call, as well as extend or modify the Panel's default dropdowns.

Dropdowns are defined as a part of areas. The key of a dropdown is its name and, unless you set a pattern, also its route. The options handler returns the list of options:

/site/plugins/todos/index.php
<?php

Kirby::plugin(
  name: 'yourname/todos',
  extends: [
    'areas' => [
      'todos' => fn () => [
        // ... other code for the custom Panel area
        'dropdowns' => [
          'todo' => [
            'pattern' => 'todos/(:any)',
            'options' => function (string $id) {
              return [
                [
                  'text'   => 'Edit',
                  'icon'   => 'edit',
                  'dialog' => 'todos/' . $id . '/update'
                ],
                [
                  'text'   => 'Duplicate',
                  'icon'   => 'copy',
                  'dialog' => 'todos/' . $id . '/duplicate'
                ],
                '-',
                [
                  'text'   => 'Delete',
                  'icon'   => 'trash',
                  'dialog' => 'todos/' . $id . '/delete'
                ]
              ];
            }
          ]
        ]
      ]
    ]
  ]
);

A - adds a separator between options. Placeholders in the pattern are passed to options as arguments.

Load the options in your Vue component with the $dropdown() helper and the route of the dropdown:

<k-button icon="cog" @click="$refs.options.toggle()">Options</k-button>
<k-dropdown ref="options" :options="$dropdown('todos/the-todo-id')" />

Option settings

Each option can define a set of parameters to control how the option is displayed and what happens on click:

Parameter Type Description
click stringorarray The name of the event that will be triggered on click
dialog stringorarray Either a single path to a dialog or dialog settings
disabled bool Enable/disable the option
icon string The name of the option icon
link string An optional URL or path to create a link instead of a button
target string A link target, e.g. _blank
text string The label for the option
theme string A theme for the option, e.g. negative

Listen for dropdown events

When you add an option to a dropdown that isn't rendered by your own component, you can't listen to its events directly. Pass a global event as click instead:

[
  'icon'  => 'share',
  'text'  => 'Publish on Netlify',
  'click' => [
    'global'  => 'myEvent',
    'payload' => [...]
  ]
]

And listen to the event with the Panel's event bus:

this.$panel.events.on("myEvent", (payload) => {...});

Controller classes

Instead of an options closure, you can handle a dropdown with a controller class. Pass its class name as action. The class extends Kirby\Panel\Controller\DropdownController, and its load() method returns the options. Like dialog controllers, Kirby creates it with a static factory() method, if there is one, or the constructor, and passes the placeholders of the route pattern:

/site/plugins/todos/index.php
'dropdowns' => [
  'todo' => [
    'pattern' => 'todos/(:any)',
    'action'  => TodoDropdownController::class
  ]
]

Extending dropdowns

Pages, files and users have dynamic option dropdowns. Those dropdowns show all the available options like changing titles, sorting pages, deleting stuff, etc. You can extend or modify them to add options, remove options or change what's shown.

Kirby merges your definition into the core definition. Define your override as an array with options (or action), so that the pattern of the core dropdown is kept. To fall back to the core options, call the core controller:

/site/plugins/netlify/index.php
<?php

use Kirby\Panel\Controller\Dropdown\PageSettingsDropdownController;

Kirby::plugin(
  name: 'example/dropdown',
  extends: [
    'areas' => [
      'site' => fn () => [
        'dropdowns' => [
          'page' => [
            'options' => function (string $id) {
              // load the core options
              $options = PageSettingsDropdownController::factory($id)->load();

              // append a separator and a new option
              $options[] = '-';
              $options[] = [
                'icon'   => 'share',
                'text'   => 'Publish on Netlify',
                'dialog' => 'publish'
              ];

              return $options;
            }
          ]
        ]
      ]
    ]
  ]
);

To remove a core dropdown, set it to false.

You find the names of all core dropdowns in the area definitions in /kirby/config/areas and their controllers in /kirby/src/Panel/Controller/Dropdown.