getUserNavigation

The getUserNavigation hook allows to manipulate the back end user navigation. It passes the back end modules and a flag wether to show collapsed navigation items. Expects the array of modules as return value.

Parameters

  1. array $modules

    The compiled list of back end modules.

  2. boolean $showAll

    Wether to show all modules even if the group is collapsed.

Return Values

Add your custom modules to the list and return the array of back end modules.

Example

// src/EventListener/GetUserNavigationListener.php
namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

#[AsHook('getUserNavigation')]
class GetUserNavigationListener
{
    public function __invoke(array $modules, bool $showAll): array
    {
        // Add custom navigation item to the Contao website
        $modules['system']['modules']['contao'] = [
            'label' => 'Contao homepage',
            'title' => 'Visit the Contao CMS website',
            'class' => 'navigation contao',
            'href' => 'https://contao.org/en/',
        ];

        return $modules;
    }
}

References