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

cargopants
cargopants

I'm creating a plugin that will make use of the backend submenu. I was able to get my Plugin name and icon to appear in the main menu just by updating my main Plugin.php registration file, but I'm not having luck getting the submenu to appear. Here is the code from my registration file:

<?php namespace Cargo\Sitewriter;

use Backend;
use Controller;
use System\Classes\PluginBase;

class Plugin extends PluginBase
{
    public function pluginDetails()
    {
        return [
            'name'        => 'Site Writer',
            'description' => 'Develop and refine your website content',
            'author'      => 'CargoPants',
            'icon'        => 'icon-sitemap'
        ];
    } 

    public function registerComponents()
    {
        return [
            'Cargo\Sitewriter\Components\Pages'       => 'sitewriterPages'
        ];
    }

    public function registerNavigation()
    {
        return [
            'siteWriter' => [
                'label'       => 'Site Writer',
                'url'         => Backend::url('cargo/sitewriter/pages'),
                'icon'        => 'icon-sitemap',
                'permissions' => ['cargo.sitewriter.*'],
                'order'       => 500,

                'sideMenu' => [
                    'newPage' => [
                        'label'       => 'New Page',
                        'icon'        => 'icon-copy',
                        'url'         => Backend::url('cargo/sitewriter/pages/'),
                        'permissions' => ['cargo.sitewriter.create_new_pages'],
                    ],
                ]
            ]
        ];
    }
}

In the registerNavigation() method, I'm creating a nested array inside of 'sideMenu'. This is how the docs referenced it. Is there more I am supposed to do to get the default backend sidebar to appear with my 'newPage' icon? The 'siteWriter' icon is appearing as it should in the main menu.

Thanks.

Last updated

Daniel81
Daniel81

You have an extra / at the end of your url in the sideMenu

cargopants
cargopants

Ah thanks. I updated the sideMenu URL, but still no sidebar. Am I required to set the context in a controller file for this to work?

Daniel81
Daniel81

Yeah, take a look at the "User" create.htm, or the "Blog" create.htm and use that code, you should get a left & right sidebar with that

cargopants
cargopants

Yep that worked. Thanks! For anyone else's reference, to get the sub-menu to appear in the backend in addition to creating the registerNavigation() function in your main Plugin.php file, you also have to "Set the context" in the Plugin controller file. Here's a link to the relevant docs:

Navigation registration: http://octobercms.com/docs/plugin/registration#navigation-permissions

Navigation context: http://octobercms.com/docs/backend/controllers-views-ajax#navigation-context

Last updated

pymarco
pymarco

Thank you @cargopants

gorbiromaric56271
gorbiromaric56271

Hi, Guys, I dont know if it is the same problem, but from my side I got the the same problem. All thing was working fine, and I change my namespace. On Linux server the folder should have the same name as the namespace. So I change my name space from Gbr\Legals to gbr\legals and I got that problem, all my Submenu disappears. To solved it, I want to all controllers files and change BackendMenu::setContext('Gbr.Legals', 'main-menu-item', 'side-menu-item4'); to BackendMenu::setContext('gbr.legals', 'main-menu-item', 'side-menu-item4'); I hope it will help someone

1-7 of 7

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