phpoctobercmsoctobercms-pluginsoctobercms-backendoctobercms-widgets

OctoberCMS backend main menu having sub menus of different plugins into it


I have one requirement in OctoberCMS which I want to implement backend (Admin side) and here below what I want to implement.

I am using Builder Plugin and I already have created so many plugins which are showing at the top of header with their respective names and links in admin (backend). And if I click on it, I can do whatever I want (CRUD operation) which works fine for all those plugins.

But now I want only one main menu (Say for example - "Plugins") and If I click on it or hover on it, I should weather be able to see all the listed plugins which I will add and can able to add in future if I create more.

I should be able to see those plugin links on hover or on left side and it should have an ability to add/remove those links.

Currently I am trying to do this in builder plugin backend menu but I am unable to do so as it is keep conflicting with code field for those menu tab. Hence I am now looking forward with some other way if I can implement.

Can someone guide me how can I achieve this ?


Solution

  • OK Guys, Eventually, I was able to make it work. This is what I have done below

    Say for example, I have 2 plugins called as Partners and Properties.

    In Partners plugin, I have coded something like this in my Plugin.php file.

    plugins\technobrave\partners\Plugin.php

    <?php namespace Technobrave\Partners;
    
    use System\Classes\PluginBase;
    use Backend;
    use Event;
    class Plugin extends PluginBase
    {
    
        public function registerNavigation()
        {
            return [
                'modules' => [
                    'label'       => 'Modules',
                    'url'         => Backend::url('technobrave/properties/properties'),
                    'icon'        => 'icon-bars',
                    'permissions' => ['Technobrave.Property.*'],
    
                    'sideMenu'    => [
                        'properties' => [
                                'label' => 'Properties',
                                'icon'        => 'icon-home',
                                'url'         => Backend::url('technobrave/properties/properties'),
                                'permissions' => ['Technobrave.Property.*']
                        ],
                        'partner' => [
                                'label' => 'Partners',
                                'icon'        => 'icon-thumbs-up',
                                'url'         => Backend::url('technobrave/partners/partners'),
                                'permissions' => ['Technobrave.Partner.*']
    
                        ], 
                         ]
                ]
            ];
        }
    

    Here, as you can see above, My header menu link will redirect to Properties plugin as per my requirement and for left side bar menus, my first link will also be redirected to Properties plugin and next sub menu link will be redirected to Partners plugin.

    Then I went to Partners controller and put code something like below.

    plugins\technobrave\partners\controllers\Partners.php

    <?php namespace Technobrave\Partners\Controllers;
    
    use Backend\Classes\Controller;
    use BackendMenu;
    
    class Partners extends Controller
    {
        public function __construct()
        {
            parent::__construct();             
            BackendMenu::setContext('Technobrave.Partners', 'modules', 'partner');        
        }
    }
    

    Here above, as you can see, I have just executed the menu into partners plugin to be able to show it when I am inside partners listing or at CRUD operation or somewhere.

    Similar thing I have done for Properties plugin as well to be able to show menu in Properties plugin. This is how my code looks like.

    plugins\technobrave\properties\controllers\Properties.php

    <?php namespace Technobrave\Properties\Controllers;
    use Backend\Classes\Controller;
    use BackendMenu;
    class Properties extends Controller
    {
        public function __construct() {
            parent::__construct();       
            BackendMenu::setContext('Technobrave.Partners', 'modules', 'properties');
        }
    }
    

    One thing to note here in this code BackendMenu::setContext('Technobrave.Partners', 'modules', 'properties');

    The Last argument is different than what we have put in Partners plugin. BackendMenu::setContext('Technobrave.Partners', 'modules', 'properties'); This is to set as default selected menu from the list at left sidebar.

    Hope this helps.