From 96fafb26206616a1dd054a679819f27c12e18d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Thu, 5 Apr 2018 08:41:23 +0200 Subject: [PATCH] EZEE-1914: Landing Page preview doesn't work when content.tree_root configuration is used --- Controller/PageController.php | 49 +++++++++++++++++++++++++++++- Resources/config/services.yml | 4 +++ Resources/translations/ezplatformee.en.xlf | 5 +++ Resources/views/page/page.html.twig | 9 +----- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Controller/PageController.php b/Controller/PageController.php index 4cf8c3da..27462ce5 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -8,12 +8,18 @@ use eZ\Publish\API\Repository\URLAliasService; use eZ\Publish\API\Repository\Values\Content\Location; use eZ\Publish\Core\MVC\ConfigResolverInterface; +use eZ\Publish\Core\MVC\Symfony\SiteAccess; use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentCreateData; use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData; use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory; +use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface; use EzSystems\EzPlatformAdminUiBundle\Controller\Controller; use EzSystems\PlatformUIBundle\ApplicationConfig\Provider; use EzSystems\StudioUIBundle\SiteAccess\ReverseMatcher; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\RouterInterface; +use EzSystems\EzPlatformAdminUi\Specification\SiteAccess\IsAdmin; +use Symfony\Component\Translation\TranslatorInterface; class PageController extends Controller { @@ -41,9 +47,21 @@ class PageController extends Controller /** @var ReverseMatcher */ private $reverseMatcher; + /** @var \Symfony\Component\Routing\RouterInterface */ + private $router; + + /** @var \EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface */ + private $notificationHandler; + + /** @var \Symfony\Component\Translation\TranslatorInterface */ + private $translator; + /** @var mixed */ private $rootLocationId; + /** @var array */ + private $siteAccessGroups; + public function __construct( Provider $configAggregator, FormFactory $formFactory, @@ -53,7 +71,11 @@ public function __construct( ConfigResolverInterface $configResolver, URLAliasService $urlAliasService, ReverseMatcher $reverseMatcher, - $rootLocationId + RouterInterface $router, + NotificationHandlerInterface $notificationHandler, + TranslatorInterface $translator, + $rootLocationId, + array $siteAccessGroups ) { $this->configAggregator = $configAggregator; $this->formFactory = $formFactory; @@ -63,7 +85,11 @@ public function __construct( $this->configResolver = $configResolver; $this->urlAliasService = $urlAliasService; $this->reverseMatcher = $reverseMatcher; + $this->router = $router; + $this->notificationHandler = $notificationHandler; + $this->translator = $translator; $this->rootLocationId = $rootLocationId; + $this->siteAccessGroups = $siteAccessGroups; } public function pageAction($locationId, $languageCode) @@ -89,6 +115,21 @@ public function pageAction($locationId, $languageCode) $contentCreateForm = $this->getContentCreateForm(); $contentEditDataForm = $this->getContentEditDataForm(); + if (empty($siteaccesses)) { + $this->notificationHandler->error($this->translator->trans( + /** @Desc("Content cannot be edited in landing page editor: couldn't find non-administrative siteaccess with location id = %location%") */ + 'error.missing.siteaccess', + ['%location%' => $location->id], + 'ezplatformee' + )); + + return $this->redirectToLocation($location); + } + + $pageUri = $this->router->generate($location, [ + 'siteaccess' => $siteaccesses[0], + ], UrlGeneratorInterface::ABSOLUTE_URL); + return $this->render( 'eZStudioUIBundle:page:page.html.twig', [ @@ -98,6 +139,8 @@ public function pageAction($locationId, $languageCode) 'siteaccesses' => $siteaccesses, 'aliases' => $aliases, 'uri_root' => $uriRoot, + 'page_uri' => $pageUri, + 'default_siteaccess' => $siteaccesses[0], 'parameters' => $this->configAggregator->getConfig(), 'form_content_create' => $contentCreateForm->createView(), 'form_content_edit' => $contentEditDataForm->createView(), @@ -139,6 +182,10 @@ private function getRelatedSiteaccesses($languageCode, $location) continue; } + if ((new IsAdmin($this->siteAccessGroups))->isSatisfiedBy(new SiteAccess(($siteaccess)))) { + continue; + } + $existsInSiteaccesses[] = $siteaccess; } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 399b1c30..d4d1b690 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -107,7 +107,11 @@ services: - '@ezpublish.config.resolver' - '@ezpublish.api.service.url_alias' - '@ezstudioui.reverse_matcher' + - '@router' + - '@EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface' + - '@translator' - '$content.tree_root.location_id$' + - '%ezpublish.siteaccess.groups%' tags: ['controller.service_arguments'] calls: - [setContainer, ["@service_container"]] diff --git a/Resources/translations/ezplatformee.en.xlf b/Resources/translations/ezplatformee.en.xlf index 5acad5b9..1cb7187b 100644 --- a/Resources/translations/ezplatformee.en.xlf +++ b/Resources/translations/ezplatformee.en.xlf @@ -11,6 +11,11 @@ Page key: ezplatform_ee_landing_page + + Content cannot be edited in landing page editor. Non-administrative siteaccess with location ID = %location% was not found. + Content cannot be edited in landing page editor. Non-administrative siteaccess with location ID = %location% was not found. + key: error.missing.siteaccess + diff --git a/Resources/views/page/page.html.twig b/Resources/views/page/page.html.twig index ce721ce5..8c5eaec6 100644 --- a/Resources/views/page/page.html.twig +++ b/Resources/views/page/page.html.twig @@ -55,13 +55,6 @@

{{ 'javascript.disabled.required'|trans }}

{{ 'javascript.enable'|trans }}

- {% set page_uri = '' %} - {% set default_siteaccess = '' %} - {% if siteaccesses|length > 0 and aliases|length > 0 %} - {% set default_siteaccess = siteaccesses[0] %} - {% set page_view_alias = aliases|length > 0 ? aliases[0] : null %} - {% set page_uri = uri_root[default_siteaccess] ~ page_view_alias.path %} - {% endif %} {% javascripts 'bundles/bazingajstranslation/js/translator.min.js' 'bundles/ezplatformuiassets/vendors/yui3/build/yui/yui-min.js' @@ -87,7 +80,7 @@ plugins: Y.eZ.PluginRegistry.getPlugins(Y.eZ.PlatformUIApp.NAME), userId: {{ admin_ui_config.user.user.id }}, startingContentUrl: '{{ page_uri }}', - studioActiveSiteaccess: '{{ default_siteaccess is not empty ? default_siteaccess : parameters.defaultSiteAccess }}' + studioActiveSiteaccess: '{{ default_siteaccess }}' }); app.on('ready', function () { Y.one(Y.config.doc.documentElement).addClass('ez-platformui-app-ready');