From 44a14fa90711f895bf2876be25710f13fb55770e Mon Sep 17 00:00:00 2001 From: Jakub Brzegowski Date: Wed, 22 Nov 2023 15:23:05 +0100 Subject: [PATCH] IBX-7051: Preview button with siteaccess (#995) --- phpstan-baseline.neon | 5 -- src/bundle/Controller/ContentController.php | 11 +++ src/bundle/Resources/config/routing.yaml | 2 + .../translations/ibexa_menu.en.xliff | 5 ++ .../admin/content/content_preview.html.twig | 19 ++++-- src/lib/Menu/ContentRightSidebarBuilder.php | 68 ++++++++++++++++++- .../ValueObjectVisitor/ContentTree/Node.php | 6 ++ src/lib/REST/Value/ContentTree/Node.php | 16 +++++ src/lib/UI/Module/ContentTree/NodeFactory.php | 47 ++++++++++++- 9 files changed, 166 insertions(+), 13 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c023bdaefe..49a85a07b8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -9775,11 +9775,6 @@ parameters: count: 1 path: src/lib/UI/Module/ContentTree/NodeFactory.php - - - message: "#^Parameter \\#9 \\$totalChildrenCount of class Ibexa\\\\AdminUi\\\\REST\\\\Value\\\\ContentTree\\\\Node constructor expects int, int\\|null given\\.$#" - count: 1 - path: src/lib/UI/Module/ContentTree/NodeFactory.php - - message: "#^Property Ibexa\\\\AdminUi\\\\UI\\\\Module\\\\ContentTree\\\\NodeFactory\\:\\:\\$bookmarkService is never read, only written\\.$#" count: 1 diff --git a/src/bundle/Controller/ContentController.php b/src/bundle/Controller/ContentController.php index 6dd9009c53..5352b23540 100644 --- a/src/bundle/Controller/ContentController.php +++ b/src/bundle/Controller/ContentController.php @@ -344,11 +344,14 @@ public function updateMainLocationAction(Request $request): Response * @return \Symfony\Component\HttpFoundation\Response */ public function previewAction( + Request $request, Content $content, ?string $languageCode = null, ?int $versionNo = null, ?Location $location = null ): Response { + $preselectedSiteAccess = $request->query->get('preselectedSiteAccess'); + if (null === $languageCode) { $languageCode = $content->contentInfo->mainLanguageCode; } @@ -379,12 +382,20 @@ public function previewAction( $siteAccessesList[$siteAccess->name] = $this->siteAccessNameGenerator->generate($siteAccess); } + if ( + $preselectedSiteAccess !== null && + !array_key_exists($preselectedSiteAccess, $siteAccessesList) + ) { + $preselectedSiteAccess = null; + } + return $this->render('@ibexadesign/content/content_preview.html.twig', [ 'location' => $location, 'content' => $content, 'language_code' => $languageCode, 'siteaccesses' => $siteAccessesList, 'version_no' => $versionNo ?? $content->getVersionInfo()->versionNo, + 'preselected_site_access' => $preselectedSiteAccess, ]); } diff --git a/src/bundle/Resources/config/routing.yaml b/src/bundle/Resources/config/routing.yaml index c847b35cb2..a93f27d90c 100644 --- a/src/bundle/Resources/config/routing.yaml +++ b/src/bundle/Resources/config/routing.yaml @@ -559,6 +559,8 @@ ibexa.content.preview: _controller: 'Ibexa\Bundle\AdminUi\Controller\ContentController::previewAction' languageCode: ~ locationId: ~ + options: + expose: true # IBX-1079: Translate routes with proxy suffix have to be prioritized to avoid issues with URL generations ibexa.content.translate.proxy: diff --git a/src/bundle/Resources/translations/ibexa_menu.en.xliff b/src/bundle/Resources/translations/ibexa_menu.en.xliff index 8d9f5d09af..2bbde169e5 100644 --- a/src/bundle/Resources/translations/ibexa_menu.en.xliff +++ b/src/bundle/Resources/translations/ibexa_menu.en.xliff @@ -46,6 +46,11 @@ Move key: content__sidebar_right__move + + Preview + Preview + key: content__sidebar_right__preview + Reveal Reveal diff --git a/src/bundle/Resources/views/themes/admin/content/content_preview.html.twig b/src/bundle/Resources/views/themes/admin/content/content_preview.html.twig index 3e863ef8c0..bda6393db1 100644 --- a/src/bundle/Resources/views/themes/admin/content/content_preview.html.twig +++ b/src/bundle/Resources/views/themes/admin/content/content_preview.html.twig @@ -3,6 +3,7 @@ {% trans_default_domain 'ibexa_content_preview' %} {% set is_published = content.contentInfo.published and content.contentInfo.mainLocationId is not null %} +{% set preselected_site_access = preselected_site_access|default(siteaccesses|first) %} {% block body_class %}ibexa-content-preview{% endblock %} @@ -23,25 +24,29 @@
{% set value = '' %} - {% set choices = siteaccesses|map((site_accesses_name, site_access_label) => { + {% set choices = siteaccesses|map((site_access_name, site_access_label) => { value: path( 'ibexa.version.preview', { 'contentId': content.id, 'versionNo': version_no, 'language': language_code, - 'siteAccessName': site_accesses_name + 'siteAccessName': site_access_name } ), - label: site_access_label|trans({}, 'ezplatform_siteaccess') + label: site_access_label|trans({}, 'ezplatform_siteaccess'), + is_selected: site_access_name == preselected_site_access, }) %} {% set source %}