Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6965: Set preview active in the PreviewRequestListener #395

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -35,6 +40,8 @@ public static function getSubscribedEvents(): array
*/
public function onKernelRequest(RequestEvent $event): void
{
$this->contentPreviewHelper->setPreviewActive(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would cause every request to set preview as active, since it subscribes to all KernelEvents::REQUEST events. You need to move this to the block actually determining that it's a preview request - see L50-52.

Looks like it's not as straightforward as it seems, so please see if there's a test coverage for this subscriber and if not please add a unit one covering 2 cases: 1) it's a preview, 2) it's not a preview.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are obviously right, not sure what I was thinking. What is more, adding it to the lines you've mentioned won't work either as a fragment request is in fact a master request. I think this PR becomes obsolete as of now.


if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion eZ/Bundle/EzPublishCoreBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
Loading