How to rename a 3rd party plugin menu item label

We usually do something like this in the boot function of our plugin to change the label of another’s nav item. It appears you can pass only the data you wish to replace.

Event::listen('backend.menu.extendItems', function($manager){
    $manager->addMainMenuItems('Author.Plugin', [
        'existing_menu_item_code' => [
            'label' => 'NEW LABEL',
        ],
    ]);
});

Thanks, it renames the menu label but there is a unwanted side-effect, as it hides the sidebar menu for some reasons.

Forcing the context seems to address this. Please refer to the rough example below which replaces the RainLab.User navigation references of “user” with “member” and forces the navigation context based on the active controller.

/**
 * Replaces Rainlab.User navigation items "user" with "member"
 */
Event::listen('backend.menu.extendItems', function($manager){
    $manager->addMainMenuItems('Rainlab.User', [
        'user' => [
            'label' => 'Members',
        ],
    ]);
    $manager->addSideMenuItems('Rainlab.User', 'user', [
        'users' => [
            'label' => 'Members',
        ],
        'usergroups' => [
            'label' => 'Member Groups',
        ],
    ]);
});

/**
 * Forces RainLab.User navigation context based on controller
 */
Event::listen('backend.page.beforeDisplay', function ($controller, $action, $params){
    if($controller instanceof \RainLab\User\Controllers\UserGroups){
        BackendMenu::setContext('Rainlab.User', 'user', 'usergroups');
    }
    elseif($controller instanceof \RainLab\User\Controllers\Users){
        BackendMenu::setContext('Rainlab.User', 'user', 'users');
    }
});
2 Likes