Skip to content

Commit

Permalink
Allowed injecting view type into content preview controller
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Oct 20, 2023
1 parent 2c1d41d commit 411344c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/bundle/Core/Resources/config/routing/internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 17 additions & 17 deletions src/lib/MVC/Symfony/Controller/Content/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
);
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 411344c

Please sign in to comment.