Configure the Admin Menu

Pushword\Admin\Controller\AdminMenu dispatches AdminMenuItemsEvent (pushword.admin.menu_items) while building the menu. Subscribe to it to add, change or replace items. Each item carries a weight; items are sorted by weight, highest first.

Adding an item

<?php

namespace App\EventSubscriber;

use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use Pushword\Admin\Menu\AdminMenuItemsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final readonly class AdminMenuSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [AdminMenuItemsEvent::NAME => 'onMenuItems'];
    }

    public function onMenuItems(AdminMenuItemsEvent $event): void
    {
        $event->addMenuItem(
            MenuItem::linkToRoute('My Custom Page', 'fa fa-star', 'my_custom_route'),
            450,
        );
    }
}

Any EasyAdmin MenuItem works: linkTo(MyCrudController::class, 'Label', 'fa fa-icon'), linkToRoute(), linkToUrl(), subMenu('Label', 'fa fa-icon')->setSubItems([...]), section('Title').

For a single route item, extend Pushword\Admin\Menu\AbstractRouteMenuItemSubscriber (the template editor does):

final readonly class AdminMenuItemSubscriber extends AbstractRouteMenuItemSubscriber
{
    public function __construct()
    {
        parent::__construct('Template Editor', 'fa fa-code', 'admin_template_editor_list', 200);
    }
}

AbstractRouteMenuWithHostsSubscriber takes the SiteRegistry first and turns the item into a per-host submenu when several sites are configured (used by the page scanner).

Default weights

WeightItem
1000Pages
900Redirections
800Media
750Cheat sheet
700Users (ROLE_SUPER_ADMIN only)
670Social posts (repurpose)
660Quiz results
650Snippets
620Newsletter
600Conversation
580Reviews (conversation, when enabled)
500Tools section
400Page scanner
350Git status (flat)
300Static generator, Activity log (version)
200Template editor

Replacing the menu

getItems() returns array<int, array{weight: int, item: MenuItemInterface}>; setItems() replaces it:

public function onMenuItems(AdminMenuItemsEvent $event): void
{
    $items = array_filter($event->getItems(), static fn (array $item): bool => $item['weight'] >= 500);
    $items[] = ['weight' => 100, 'item' => MenuItem::linkToRoute('Custom', 'fa fa-cog', 'custom_route')];

    $event->setItems($items);
}