From 411344c1d434161d7d89a1824b5691f4ecced0fb Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 19 Oct 2023 15:07:50 +0200 Subject: [PATCH] Allowed injecting view type into content preview controller --- .../Resources/config/routing/internal.yml | 2 +- .../Controller/Content/PreviewController.php | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/bundle/Core/Resources/config/routing/internal.yml b/src/bundle/Core/Resources/config/routing/internal.yml index 54823daa02..9a15b9179b 100644 --- a/src/bundle/Core/Resources/config/routing/internal.yml +++ b/src/bundle/Core/Resources/config/routing/internal.yml @@ -20,7 +20,7 @@ ibexa.content.view: ibexa.version.preview: path: /content/versionview/{contentId}/{versionNo}/{language}/site_access/{siteAccessName} - defaults: { _controller: ibexa.controller.content.preview:previewContentAction } + controller: ibexa.controller.content.preview:previewContentAction methods: [GET] ibexa.content.preview.default: diff --git a/src/lib/MVC/Symfony/Controller/Content/PreviewController.php b/src/lib/MVC/Symfony/Controller/Content/PreviewController.php index ee706a62d3..88bfd9a19b 100644 --- a/src/lib/MVC/Symfony/Controller/Content/PreviewController.php +++ b/src/lib/MVC/Symfony/Controller/Content/PreviewController.php @@ -22,6 +22,7 @@ use Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker; use Ibexa\Core\MVC\Symfony\View\ViewManagerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; @@ -77,12 +78,12 @@ public function __construct( */ public function previewContentAction( Request $request, - $contentId, - $versionNo, - $language, - $siteAccessName = null, + int $contentId, + int $versionNo, + string $language, + ?string $siteAccessName = null, ?int $locationId = null - ) { + ): Response { $this->previewHelper->setPreviewActive(true); try { @@ -112,8 +113,9 @@ public function previewContentAction( } try { + $viewType = $request->query->get('viewType') ?? ViewManagerInterface::VIEW_TYPE_FULL; $response = $this->kernel->handle( - $this->getForwardRequest($location, $content, $siteAccess, $request, $language), + $this->getForwardRequest($location, $content, $siteAccess, $request, $language, $viewType), HttpKernelInterface::SUB_REQUEST, false ); @@ -140,17 +142,15 @@ public function previewContentAction( /** * Returns the Request object that will be forwarded to the kernel for previewing the content. - * - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content - * @param \Ibexa\Core\MVC\Symfony\SiteAccess $previewSiteAccess - * @param \Symfony\Component\HttpFoundation\Request $request - * @param string $language - * - * @return \Symfony\Component\HttpFoundation\Request */ - protected function getForwardRequest(Location $location, Content $content, SiteAccess $previewSiteAccess, Request $request, $language) - { + protected function getForwardRequest( + Location $location, + Content $content, + SiteAccess $previewSiteAccess, + Request $request, + string $language, + string $viewType = ViewManagerInterface::VIEW_TYPE_FULL + ): Request { $forwardRequestParameters = [ '_controller' => UrlAliasRouter::VIEW_ACTION, // specify a route for RouteReference generator @@ -161,7 +161,7 @@ protected function getForwardRequest(Location $location, Content $content, SiteA ], 'location' => $location, 'content' => $content, - 'viewType' => ViewManagerInterface::VIEW_TYPE_FULL, + 'viewType' => $viewType, 'layout' => true, 'params' => [ 'content' => $content,