vendor/ibexa/dashboard/src/lib/EventSubscriber/AddDashboardContentTypeGroupUIConfigSubscriber.php line 40

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\Dashboard\EventSubscriber;
  8. use Ibexa\AdminUi\Event\AddContentTypeGroupToUIConfigEvent;
  9. use Ibexa\Contracts\Core\Repository\ContentTypeService;
  10. use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
  11. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. final class AddDashboardContentTypeGroupUIConfigSubscriber implements EventSubscriberInterface
  14. {
  15.     public const CONTENT_TYPE_IDENTIFIER_PARAM_NAME 'dashboard.content_type_group_identifier';
  16.     private ConfigResolverInterface $configResolver;
  17.     private ContentTypeService $contentTypeService;
  18.     public function __construct(
  19.         ConfigResolverInterface $configResolver,
  20.         ContentTypeService $contentTypeService
  21.     ) {
  22.         $this->configResolver $configResolver;
  23.         $this->contentTypeService $contentTypeService;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             AddContentTypeGroupToUIConfigEvent::class => ['addDashboardContentTypeGroup'],
  29.         ];
  30.     }
  31.     public function addDashboardContentTypeGroup(AddContentTypeGroupToUIConfigEvent $event): void
  32.     {
  33.         $dashboardContentTypeGroupIdentifier $this->configResolver->getParameter(
  34.             self::CONTENT_TYPE_IDENTIFIER_PARAM_NAME,
  35.         );
  36.         try {
  37.             $dashboardContentTypeGroup $this->contentTypeService->loadContentTypeGroupByIdentifier(
  38.                 $dashboardContentTypeGroupIdentifier
  39.             );
  40.         } catch (NotFoundException $e) {
  41.             return;
  42.         }
  43.         $event->addContentTypeGroup($dashboardContentTypeGroup);
  44.     }
  45. }