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

aaron.humphreys
aaron.humphreys

I am looking at developing a series of stand alone plugins. However, I do not wish to create a new top level menu for each one.

Is there a method to registerNavigation once. Then on a new plugin, append new side menu items to the existing menu?

patrickward
patrickward

You can use the backend.menu.extendItems event to add new side menu items. For example, with the RainLab User plugin you can do the following from within your Plugin.php file:

  /**
   * Boot the plugin
   */
  public function boot()
  {

    Event::listen('backend.menu.extendItems', function($manager) {

        // Add new side menu items 
        // parameters: Plugin ID, Menu Code, Menu Definitions. 
        $manager->addSideMenuItems('RainLab.User', 'user', [
            'imports' => [
            'label' => 'Imports',
            'icon'  => 'icon-upload',
            'code'  => 'imports',
            'owner' => 'RainLab.User',
            'url'   => Backend::url('myplugin/user/imports')
            ],
            'messages' => [
            'label' => 'Messages',
            'icon'  => 'icon-envelope',
            'code'  => 'messages',
            'owner' => 'RainLab.User',
            'url'   => Backend::url('myplugin/user/messages')
            ]
        ]);

        });
  }
Fibonacci
Fibonacci

thank you @Patrickward.

But, how to hold the default side menu items from Rainlab.User? Because, when I click my side menu in rainlab.user, it's redirect to my plugin and the side menu (Rainlab.user) disappear.

Thanks,

patrickward
patrickward

Hi @Fibonacci, I believe you're referring to the navigation context. In your controller, you can set the backend menu context to refer to the RainLab.User context inside of the constructor. This is how I did it for a recent plugin:

    public function __construct()
    {
        parent::__construct();

        BackendMenu::setContext('RainLab.User', 'user', 'imports');
    }

That tells October which menu and submenu is active. The documentation has some additional information that may be of use to you.

Hope that helps.

Fibonacci
Fibonacci

Thank you @Patrickward. Really help.

1-5 of 5

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