vendor/ibexa/admin-ui/src/lib/Tab/Event/Subscriber/ConditionalTabSubscriber.php line 48

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\AdminUi\Tab\Event\Subscriber;
  8. use Ibexa\AdminUi\Tab\Event\TabEvents;
  9. use Ibexa\AdminUi\Tab\Event\TabGroupEvent;
  10. use Ibexa\AdminUi\UI\Service\TabService;
  11. use Ibexa\Contracts\AdminUi\Tab\ConditionalTabInterface;
  12. use InvalidArgumentException;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15.  * Evaluates if tabs should be visible (Tabs implementing ConditionalTabInterface).
  16.  *
  17.  * @see \Ibexa\Contracts\AdminUi\Tab\ConditionalTabInterface
  18.  */
  19. class ConditionalTabSubscriber implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var \Ibexa\AdminUi\UI\Service\TabService
  23.      */
  24.     private $tabService;
  25.     public function __construct(TabService $tabService)
  26.     {
  27.         $this->tabService $tabService;
  28.     }
  29.     /**
  30.      * @return array
  31.      */
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             TabEvents::TAB_GROUP_INITIALIZE => ['onTabGroupInitialize'],
  36.         ];
  37.     }
  38.     /**
  39.      * @param \Ibexa\AdminUi\Tab\Event\TabGroupEvent $tabGroupEvent
  40.      */
  41.     public function onTabGroupInitialize(TabGroupEvent $tabGroupEvent)
  42.     {
  43.         $tabGroup $tabGroupEvent->getData();
  44.         $tabGroupIdentifier $tabGroupEvent->getData()->getIdentifier();
  45.         $parameters $tabGroupEvent->getParameters();
  46.         try {
  47.             $tabs $this->tabService->getTabGroup($tabGroupIdentifier)->getTabs();
  48.         } catch (InvalidArgumentException $e) {
  49.             $tabs = [];
  50.         }
  51.         foreach ($tabs as $tab) {
  52.             if (!$tab instanceof ConditionalTabInterface || $tab->evaluate($parameters)) {
  53.                 $tabGroup->addTab($tab);
  54.             }
  55.         }
  56.         $tabGroupEvent->setData($tabGroup);
  57.     }
  58. }
  59. class_alias(ConditionalTabSubscriber::class, 'EzSystems\EzPlatformAdminUi\Tab\Event\Subscriber\ConditionalTabSubscriber');