vendor/ezsystems/ezplatform-admin-ui/src/lib/Tab/Event/Subscriber/ConditionalTabSubscriber.php line 49

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems 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 EzSystems\EzPlatformAdminUi\Tab\Event\Subscriber;
  8. use EzSystems\EzPlatformAdminUi\Tab\ConditionalTabInterface;
  9. use EzSystems\EzPlatformAdminUi\Tab\Event\TabEvents;
  10. use EzSystems\EzPlatformAdminUi\Tab\Event\TabGroupEvent;
  11. use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface;
  12. use EzSystems\EzPlatformAdminUi\UI\Service\TabService;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15.  * Reorders tabs according to their Order value (Tabs implementing OrderedTabInterface).
  16.  * Tabs without order specified are pushed to the end of the group.
  17.  *
  18.  * @see OrderedTabInterface
  19.  */
  20. class ConditionalTabSubscriber implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @var \EzSystems\EzPlatformAdminUi\UI\Service\TabService
  24.      */
  25.     private $tabService;
  26.     public function __construct(TabService $tabService)
  27.     {
  28.         $this->tabService $tabService;
  29.     }
  30.     /**
  31.      * @return array
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             TabEvents::TAB_GROUP_INITIALIZE => ['onTabGroupInitialize'],
  37.         ];
  38.     }
  39.     /**
  40.      * @param TabGroupEvent $tabGroupEvent
  41.      */
  42.     public function onTabGroupInitialize(TabGroupEvent $tabGroupEvent)
  43.     {
  44.         $tabGroup $tabGroupEvent->getData();
  45.         $tabGroupIdentifier $tabGroupEvent->getData()->getIdentifier();
  46.         $parameters $tabGroupEvent->getParameters();
  47.         $tabs $this->tabService->getTabGroup($tabGroupIdentifier)->getTabs();
  48.         foreach ($tabs as $tab) {
  49.             if (!$tab instanceof ConditionalTabInterface || $tab->evaluate($parameters)) {
  50.                 $tabGroup->addTab($tab);
  51.             }
  52.         }
  53.         $tabGroupEvent->setData($tabGroup);
  54.     }
  55. }