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 19, 2023
1 parent 3a2be98 commit e258eae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
12 changes: 10 additions & 2 deletions src/bundle/Core/Resources/config/routing/internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ ibexa.content.view:
expose: true

ibexa.version.preview:
path: /content/versionview/{contentId}/{versionNo}/{language}/site_access/{siteAccessName}
defaults: { _controller: ibexa.controller.content.preview:previewContentAction }
path: /content/versionview/{contentId}/{versionNo}/{language}/site_access/{siteAccessName}/{viewType}
controller: ibexa.controller.content.preview:previewContentAction
defaults:
viewType: !php/const \Ibexa\Core\MVC\Symfony\View\ViewManagerInterface::VIEW_TYPE_FULL
requirements:
contentId: '\d+'
versionNo: '\d+'
language: '\s+'
siteAccessName: '\s+'
viewType: '\s+'
methods: [GET]

ibexa.content.preview.default:
Expand Down
36 changes: 18 additions & 18 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,13 @@ public function __construct(
*/
public function previewContentAction(
Request $request,
$contentId,
$versionNo,
$language,
$siteAccessName = null,
?int $locationId = null
) {
int $contentId,
int $versionNo,
string $language,
?string $siteAccessName = null,
?int $locationId = null,
string $viewType = ViewManagerInterface::VIEW_TYPE_FULL
): Response {
$this->previewHelper->setPreviewActive(true);

try {
Expand Down Expand Up @@ -113,7 +115,7 @@ public function previewContentAction(

try {
$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 e258eae

Please sign in to comment.