From fdc23f55af4b10158844dc8cbd509e8640a8a8d7 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 27 Nov 2023 15:44:07 +0100 Subject: [PATCH] IBX-6965: Set preview active in the `PreviewRequestListener` --- .../EventListener/PreviewRequestListener.php | 9 ++++++++- .../EzPublishCoreBundle/Resources/config/routing.yml | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/eZ/Bundle/EzPublishCoreBundle/EventListener/PreviewRequestListener.php b/eZ/Bundle/EzPublishCoreBundle/EventListener/PreviewRequestListener.php index 44a1ba952b..c9103d22a3 100644 --- a/eZ/Bundle/EzPublishCoreBundle/EventListener/PreviewRequestListener.php +++ b/eZ/Bundle/EzPublishCoreBundle/EventListener/PreviewRequestListener.php @@ -6,6 +6,7 @@ */ namespace eZ\Bundle\EzPublishCoreBundle\EventListener; +use eZ\Publish\Core\Helper\ContentPreviewHelper; use eZ\Publish\Core\MVC\Symfony\Controller\Content\PreviewController; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -18,9 +19,13 @@ class PreviewRequestListener implements EventSubscriberInterface /** @var \Symfony\Component\HttpFoundation\RequestStack */ private $requestStack; - public function __construct(RequestStack $requestStack) + /** @var \eZ\Publish\Core\Helper\ContentPreviewHelper */ + private $contentPreviewHelper; + + public function __construct(RequestStack $requestStack, ContentPreviewHelper $contentPreviewHelper) { $this->requestStack = $requestStack; + $this->contentPreviewHelper = $contentPreviewHelper; } public static function getSubscribedEvents(): array @@ -35,6 +40,8 @@ public static function getSubscribedEvents(): array */ public function onKernelRequest(RequestEvent $event): void { + $this->contentPreviewHelper->setPreviewActive(true); + if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { return; } diff --git a/eZ/Bundle/EzPublishCoreBundle/Resources/config/routing.yml b/eZ/Bundle/EzPublishCoreBundle/Resources/config/routing.yml index baadcbe5bc..1bcd82d005 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Resources/config/routing.yml +++ b/eZ/Bundle/EzPublishCoreBundle/Resources/config/routing.yml @@ -152,7 +152,9 @@ services: ezpublish.preview_request_listener: class: eZ\Bundle\EzPublishCoreBundle\EventListener\PreviewRequestListener - arguments: ["@request_stack"] + arguments: + $requestStack: '@request_stack' + $contentPreviewHelper: '@ezpublish.content_preview_helper' tags: - { name: kernel.event_subscriber }