vendor/ibexa/dashboard/src/bundle/Menu/ConfigureMainMenuListener.php line 40

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\Dashboard\Menu;
  8. use Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent;
  9. use Ibexa\AdminUi\Menu\MainMenuBuilder;
  10. use Ibexa\AdminUi\Menu\MenuItemFactory;
  11. use Ibexa\Contracts\Core\Repository\LocationService;
  12. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  13. use JMS\TranslationBundle\Model\Message;
  14. use JMS\TranslationBundle\Translation\TranslationContainerInterface;
  15. final class ConfigureMainMenuListener implements TranslationContainerInterface
  16. {
  17.     public const ITEM_ADMIN__DASHBOARD 'main__admin__dashboard';
  18.     public const ITEM_ADMIN__DASHBOARD_CONTENT_TYPE 'main__admin__dashboard_content_type';
  19.     private MenuItemFactory $menuItemFactory;
  20.     private ConfigResolverInterface $configResolver;
  21.     private LocationService $locationService;
  22.     public function __construct(
  23.         MenuItemFactory $menuItemFactory,
  24.         ConfigResolverInterface $configResolver,
  25.         LocationService $locationService
  26.     ) {
  27.         $this->menuItemFactory $menuItemFactory;
  28.         $this->configResolver $configResolver;
  29.         $this->locationService $locationService;
  30.     }
  31.     public function onMenuConfigure(ConfigureMenuEvent $event): void
  32.     {
  33.         $menu $event->getMenu();
  34.         $adminMenu $menu->getChild(MainMenuBuilder::ITEM_ADMIN);
  35.         if (null === $adminMenu) {
  36.             return;
  37.         }
  38.         $dashboardLocationRemoteId $this->configResolver->getParameter('dashboard.container_remote_id');
  39.         $location $this->locationService->loadLocationByRemoteId($dashboardLocationRemoteId);
  40.         $dashboardsLocationMenuItem $this->menuItemFactory->createLocationMenuItem(
  41.             self::ITEM_ADMIN__DASHBOARD,
  42.             $location->id,
  43.             [
  44.                 'extras' => [
  45.                     'orderNumber' => 20,
  46.                 ],
  47.             ]
  48.         );
  49.         if (null !== $dashboardsLocationMenuItem) {
  50.             $adminMenu->addChild($dashboardsLocationMenuItem);
  51.         }
  52.         $dashboardContentTypeMenuItem $this->menuItemFactory->createItem(
  53.             self::ITEM_ADMIN__DASHBOARD_CONTENT_TYPE,
  54.             [
  55.                 'route' => 'ibexa.dashboard.content_type',
  56.                 'extras' => [
  57.                     'orderNumber' => 20,
  58.                 ],
  59.             ],
  60.         );
  61.         $adminMenu->addChild($dashboardContentTypeMenuItem);
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public static function getTranslationMessages(): array
  67.     {
  68.         return [
  69.             (new Message(self::ITEM_ADMIN__DASHBOARD'ibexa_menu'))->setDesc('Dashboards'),
  70.             (new Message(self::ITEM_ADMIN__DASHBOARD_CONTENT_TYPE'ibexa_menu'))
  71.                 ->setDesc('Dashboard type'),
  72.         ];
  73.     }
  74. }