vendor/ibexa/storefront/src/bundle/EventSubscriber/ViewTemplatesSubscriber.php line 35

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\Storefront\EventSubscriber;
  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\Storefront\View;
  12. use Ibexa\Storefront\View\Order\DetailView;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. final class ViewTemplatesSubscriber implements EventSubscriberInterface
  15. {
  16. private ConfigResolverInterface $configResolver;
  17. public function __construct(
  18. ConfigResolverInterface $configResolver
  19. ) {
  20. $this->configResolver = $configResolver;
  21. }
  22. public static function getSubscribedEvents(): array
  23. {
  24. return [
  25. MVCEvents::PRE_CONTENT_VIEW => 'onPreContentView',
  26. ];
  27. }
  28. public function onPreContentView(PreContentViewEvent $event): void
  29. {
  30. $view = $event->getContentView();
  31. $pageLayout = $this->configResolver->getParameter('page_layout');
  32. if (in_array(get_class($view), $this->getTemplatesMap(), true)) {
  33. $view->addParameters(['page_layout' => $pageLayout]);
  34. }
  35. }
  36. /**
  37. * @phpstan-return class-string[]
  38. */
  39. private function getTemplatesMap(): array
  40. {
  41. return [
  42. View\Order\ListView::class,
  43. DetailView::class,
  44. ];
  45. }
  46. }