vendor/ibexa/admin-ui/src/lib/UniversalDiscovery/Event/Subscriber/ObjectRelationAllowedContentTypes.php line 29

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\UniversalDiscovery\Event\Subscriber;
  8. use Ibexa\AdminUi\UniversalDiscovery\Event\ConfigResolveEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class ObjectRelationAllowedContentTypes implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @return array
  14.      */
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             ConfigResolveEvent::NAME => ['onUdwConfigResolve'],
  19.         ];
  20.     }
  21.     /**
  22.      * @param \Ibexa\AdminUi\UniversalDiscovery\Event\ConfigResolveEvent $event
  23.      */
  24.     public function onUdwConfigResolve(ConfigResolveEvent $event): void
  25.     {
  26.         $context $event->getContext();
  27.         $config $event->getConfig();
  28.         if (!in_array($event->getConfigName(), ['single''multiple'])) {
  29.             return;
  30.         }
  31.         if (
  32.             !isset($context['type'], $context['allowed_content_types'])
  33.             || 'object_relation' !== $context['type']
  34.         ) {
  35.             return;
  36.         }
  37.         if (!empty($config['allowed_content_types'])) {
  38.             $intersection array_values(
  39.                 array_intersect(
  40.                     $config['allowed_content_types'],
  41.                     $context['allowed_content_types']
  42.                 )
  43.             );
  44.             $config['allowed_content_types'] = empty($intersection)
  45.                 ? null
  46.                 $intersection;
  47.         } else {
  48.             $config['allowed_content_types'] = empty($context['allowed_content_types'])
  49.                 ? null
  50.                 $context['allowed_content_types'];
  51.         }
  52.         $event->setConfig($config);
  53.     }
  54. }
  55. class_alias(ObjectRelationAllowedContentTypes::class, 'EzSystems\EzPlatformAdminUi\UniversalDiscovery\Event\Subscriber\ObjectRelationAllowedContentTypes');