vendor/ibexa/admin-ui/src/lib/EventListener/ViewTemplatesListener.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\AdminUi\EventListener;
  8. use Ibexa\ContentForms\User\View\UserCreateView;
  9. use Ibexa\ContentForms\User\View\UserUpdateView;
  10. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  11. use Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent;
  12. use Ibexa\Core\MVC\Symfony\MVCEvents;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15.  * Sets the templates used by the user controller.
  16.  */
  17. class ViewTemplatesListener implements EventSubscriberInterface
  18. {
  19.     /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
  20.     private $configResolver;
  21.     public function __construct(ConfigResolverInterface $configResolver)
  22.     {
  23.         $this->configResolver $configResolver;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [MVCEvents::PRE_CONTENT_VIEW => 'setViewTemplates'];
  28.     }
  29.     /**
  30.      * If the event's view has a defined template, sets the view's template identifier,
  31.      * and the 'pagelayout' parameter.
  32.      */
  33.     public function setViewTemplates(PreContentViewEvent $event): void
  34.     {
  35.         $view $event->getContentView();
  36.         $pagelayout $this->configResolver->getParameter('pagelayout');
  37.         foreach ($this->getTemplatesMap() as $viewClass => $template) {
  38.             if ($view instanceof $viewClass) {
  39.                 $view->setTemplateIdentifier($template);
  40.                 $view->addParameters(['pagelayout' => $pagelayout]);
  41.                 $view->addParameters(['page_layout' => $pagelayout]);
  42.             }
  43.         }
  44.     }
  45.     /**
  46.      * @return string[]
  47.      */
  48.     private function getTemplatesMap(): array
  49.     {
  50.         return [
  51.             UserCreateView::class => $this->configResolver->getParameter('user_edit.templates.create'),
  52.             UserUpdateView::class => $this->configResolver->getParameter('user_edit.templates.update'),
  53.         ];
  54.     }
  55. }
  56. class_alias(ViewTemplatesListener::class, 'EzSystems\EzPlatformAdminUi\EventListener\ViewTemplatesListener');