This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

mcustiel
mcustiel

Hi. I am trying to have a static menu where users can specify some custom data when adding a menu item. Right now I can add elements to the viewbag by editing ~/plugins/rainlab/pages/classes/menuitem/fields.yaml file, but I would like to do this from my own plugin to avoid overwriting if static pages plugin is updated.

Is there some way to extend the static menu item editor to have more fields or more items in the viewbag?

Thank you very much!

Crazymodder
Crazymodder

Hi, this documented in StaticPages Plugin.

In your plugin.php you can add this:

Event::listen('backend.form.extendFields', function ($widget) {

if (
    !$widget->getController() instanceof \RainLab\Pages\Controllers\Index ||
    !$widget->model instanceof \RainLab\Pages\Classes\MenuItem
) {
    return;
}

$widget->addTabFields([
    'viewBag[featured]' => [
        'tab' => 'Display',
        'label' => 'Featured',
        'comment' => 'Mark this menu item as featured',
        'type' => 'checkbox'
    ]
]);
});
mcustiel
mcustiel

Woo. I missed that!
Thank you very much for your answer.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.