vendor/ibexa/corporate-account/src/bundle/EventSubscriber/CorporatePortal/AbstractViewSubscriber.php line 43

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\Bundle\CorporateAccount\EventSubscriber\CorporatePortal;
  8. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  9. use Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent;
  10. use Ibexa\Core\MVC\Symfony\MVCEvents;
  11. use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
  12. use Ibexa\Core\MVC\Symfony\View\View;
  13. use Ibexa\CorporateAccount\Specification\IsCorporate;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. abstract class AbstractViewSubscriber implements EventSubscriberInterface
  16. {
  17.     private SiteAccessServiceInterface $siteAccessService;
  18.     private ConfigResolverInterface $configResolver;
  19.     public function __construct(
  20.         SiteAccessServiceInterface $siteAccessService,
  21.         ConfigResolverInterface $configResolver
  22.     ) {
  23.         $this->siteAccessService $siteAccessService;
  24.         $this->configResolver $configResolver;
  25.     }
  26.     /**
  27.      * @return array<string,string>
  28.      */
  29.     final public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             MVCEvents::PRE_CONTENT_VIEW => 'onPreContentView',
  33.         ];
  34.     }
  35.     final public function onPreContentView(PreContentViewEvent $event): void
  36.     {
  37.         $view $event->getContentView();
  38.         $pagelayout $this->configResolver->getParameter('page_layout');
  39.         if ($this->supports($view) && $this->isCorporatePortalSiteAccess()) {
  40.             $this->configureView($view);
  41.             $view->addParameters(['page_layout' => $pagelayout]);
  42.         }
  43.     }
  44.     /**
  45.      * Returns true if given $view is supported by subscriber.
  46.      */
  47.     abstract protected function supports(View $view): bool;
  48.     abstract protected function configureView(View $view): void;
  49.     private function isCorporatePortalSiteAccess(): bool
  50.     {
  51.         $currentSiteAccess $this->siteAccessService->getCurrent();
  52.         if ($currentSiteAccess === null) {
  53.             return false;
  54.         }
  55.         return (new IsCorporate($this->siteAccessService))->isSatisfiedBy($currentSiteAccess);
  56.     }
  57. }