vendor/ibexa/taxonomy/src/lib/Event/Subscriber/ContentViewTabSubscriber.php line 42

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\Taxonomy\Event\Subscriber;
  8. use Ibexa\AdminUi\Tab\Event\TabEvents;
  9. use Ibexa\AdminUi\Tab\Event\TabGroupEvent;
  10. use Ibexa\Taxonomy\Service\TaxonomyConfiguration;
  11. use InvalidArgumentException;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. final class ContentViewTabSubscriber implements EventSubscriberInterface
  14. {
  15.     private const UNSUPPORTED_TABS = [
  16.         'locations',
  17.         'relations',
  18.         'versions',
  19.         'ecommerce-tab',
  20.         'sub_items',
  21.     ];
  22.     private TaxonomyConfiguration $taxonomyConfiguration;
  23.     public function __construct(
  24.         TaxonomyConfiguration $taxonomyConfiguration
  25.     ) {
  26.         $this->taxonomyConfiguration $taxonomyConfiguration;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             TabEvents::TAB_GROUP_INITIALIZE => ['onTabGroupInitialize', -50],
  32.         ];
  33.     }
  34.     public function onTabGroupInitialize(TabGroupEvent $tabGroupEvent): void
  35.     {
  36.         $tabGroup $tabGroupEvent->getData();
  37.         $parameters $tabGroupEvent->getParameters();
  38.         if (
  39.             !isset($parameters['contentType'])
  40.             || $tabGroup->getIdentifier() !== 'location-view'
  41.         ) {
  42.             return;
  43.         }
  44.         /** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $contentType */
  45.         $contentType $parameters['contentType'];
  46.         if (!$this->taxonomyConfiguration->isContentTypeAssociatedWithTaxonomy($contentType)) {
  47.             return;
  48.         }
  49.         foreach (self::UNSUPPORTED_TABS as $tabIdentifier) {
  50.             try {
  51.                 $tabGroup->removeTab($tabIdentifier);
  52.             } catch (InvalidArgumentException $e) {
  53.                 continue;
  54.             }
  55.         }
  56.     }
  57. }