vendor/sonata-project/admin-bundle/src/Menu/MenuBuilder.php line 60

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\AdminBundle\Menu;
  12. use Knp\Menu\FactoryInterface;
  13. use Knp\Menu\ItemInterface;
  14. use Knp\Menu\Provider\MenuProviderInterface;
  15. use Sonata\AdminBundle\Admin\Pool;
  16. use Sonata\AdminBundle\Event\ConfigureMenuEvent;
  17. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  18. /**
  19.  * Sonata menu builder.
  20.  *
  21.  * @author Martin HasoĊˆ <martin.hason@gmail.com>
  22.  * @author Alexandru Furculita <alex@furculita.net>
  23.  */
  24. final class MenuBuilder
  25. {
  26.     public function __construct(
  27.         private Pool $pool,
  28.         private FactoryInterface $factory,
  29.         private MenuProviderInterface $provider,
  30.         private EventDispatcherInterface $eventDispatcher,
  31.     ) {
  32.     }
  33.     /**
  34.      * Builds sidebar menu.
  35.      */
  36.     public function createSidebarMenu(): ItemInterface
  37.     {
  38.         $menu $this->factory->createItem('root');
  39.         foreach ($this->pool->getAdminGroups() as $name => $group) {
  40.             $extras = [
  41.                 'icon' => $group['icon'],
  42.                 'translation_domain' => $group['translation_domain'],
  43.                 'label_catalogue' => $group['label_catalogue'] ?? ''// NEXT_MAJOR: Remove this line.
  44.                 'roles' => $group['roles'],
  45.                 'sonata_admin' => true,
  46.             ];
  47.             $menuProvider $group['provider'] ?? 'sonata_group_menu';
  48.             $subMenu $this->provider->get(
  49.                 $menuProvider,
  50.                 [
  51.                     'name' => $name,
  52.                     'group' => $group,
  53.                 ]
  54.             );
  55.             $subMenu $menu->addChild($subMenu);
  56.             $subMenu->setExtras(array_merge($subMenu->getExtras(), $extras));
  57.         }
  58.         $event = new ConfigureMenuEvent($this->factory$menu);
  59.         $this->eventDispatcher->dispatch($eventConfigureMenuEvent::SIDEBAR);
  60.         return $event->getMenu();
  61.     }
  62. }