vendor/ibexa/taxonomy/src/lib/Event/Subscriber/ContentCreateContentTypeChoiceLoaderSubscriber.php line 32

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\Form\Type\Event\ContentCreateContentTypeChoiceLoaderEvent;
  9. use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
  10. use Ibexa\Taxonomy\Service\TaxonomyConfiguration;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. final class ContentCreateContentTypeChoiceLoaderSubscriber implements EventSubscriberInterface
  13. {
  14.     private TaxonomyConfiguration $taxonomyConfiguration;
  15.     public function __construct(TaxonomyConfiguration $taxonomyConfiguration)
  16.     {
  17.         $this->taxonomyConfiguration $taxonomyConfiguration;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             ContentCreateContentTypeChoiceLoaderEvent::RESOLVE_CONTENT_TYPES => 'removeTaxonomyContentTypes',
  23.         ];
  24.     }
  25.     public function removeTaxonomyContentTypes(ContentCreateContentTypeChoiceLoaderEvent $event): void
  26.     {
  27.         $contentTypeGroups $event->getContentTypeGroups();
  28.         foreach ($contentTypeGroups as $groupIdentifier => $contentTypes) {
  29.             $contentTypes array_filter(
  30.                 $contentTypes,
  31.                 fn (ContentType $contentType): bool => !$this
  32.                     ->taxonomyConfiguration
  33.                     ->isContentTypeAssociatedWithTaxonomy($contentType)
  34.             );
  35.             $event->addContentTypeGroup($groupIdentifier$contentTypes);
  36.         }
  37.     }
  38. }