CustomAdminMenus by Robin S

Adds up to three custom dropdowns to the main admin menu.

Custom Admin Menus

Adds up to three custom menu items with optional dropdowns to the main admin menu.

The menu items can link to admin pages, front-end pages, or pages on external websites.

The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.

Requires ProcessWire v3.0.178 or newer and AdminThemeUikit.

Screenshots


Example of menu items

cam-1

Module config for the menus

cam-2

Link list shown when parent menu item is not given a URL

cam-3

Advanced


Setting child menu items dynamically

If needed you can set the child menu items dynamically using a hook.

Example:

$wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) {
    // The menu number is the first argument
    $menu_number = $event->arguments(0);
    if($menu_number === 1) {
        $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']);
        $children = [];
        foreach($colours as $colour) {
            // Each child item should be an array with the following keys
            $children[] = [
                'icon' => $colour['page_icon'],
                'label' => $colour['title'],
                'url' => $colour['url'],
                'newtab' => false,
            ];
        }
        $event->return = $children;
    }
});

Create multiple levels of flyout menus

It's also possible to create multiple levels of flyout submenus using a hook.

cam-4

For each level a submenu can be defined in a "children" item. Example:

$wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) {
    // The menu number is the first argument
    $menu_number = $event->arguments(0);
    if($menu_number === 1) {
        $children = [
            [
                'icon' => 'adjust',
                'label' => 'One',
                'url' => '/one/',
                'newtab' => false,
            ],
            [
                'icon' => 'anchor',
                'label' => 'Two',
                'url' => '/two/',
                'newtab' => false,
                'children' => [
                    [
                        'icon' => 'child',
                        'label' => 'Red',
                        'url' => '/red/',
                        'newtab' => false,
                    ],
                    [
                        'icon' => 'bullhorn',
                        'label' => 'Green',
                        'url' => '/green/',
                        'newtab' => false,
                        'children' => [
                            [
                                'icon' => 'wifi',
                                'label' => 'Small',
                                'url' => '/small/',
                                'newtab' => true,
                            ],
                            [
                                'icon' => 'codepen',
                                'label' => 'Medium',
                                'url' => '/medium/',
                                'newtab' => false,
                            ],
                            [
                                'icon' => 'cogs',
                                'label' => 'Large',
                                'url' => '/large/',
                                'newtab' => false,
                            ],
                        ]
                    ],
                    [
                        'icon' => 'futbol-o',
                        'label' => 'Blue',
                        'url' => '/blue/',
                        'newtab' => true,
                    ],
                ]
            ],
            [
                'icon' => 'hand-o-left',
                'label' => 'Three',
                'url' => '/three/',
                'newtab' => false,
            ],
        ];
        $event->return = $children;
    }
});

Showing/hiding menus according to user role

You can determine which menu items can be seen by a role by checking the user's role in the hook.

For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:

$wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) {
    // The menu number is the first argument
    $menu_number = $event->arguments(0);
    $user = $event->wire()->user;
    // For custom menu number 1...
    if($menu_number === 1) {
        // ...if user does not have some particular role...
        if(!$user->hasRole('foo')) {
            // ...do not show the menu
            $event->return = false;
        }
    }
});

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #563
    In the 563rd issue of ProcessWire Weekly we will share the latest weekly update from Ryan, as well as the latest news and updates from the ProcessWire community. Read on!
    Weekly.pw / 22 February 2025
  • ProcessWire 3.0.244 new main/master version
    ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
    Blog / 18 January 2025
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK