From febb2029822d50d48c9a0de80b0b0ae4a568fa82 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Mon, 6 Mar 2023 17:25:52 +0100 Subject: [PATCH] FEATURE: Add editPreviewMode support for Neos 9.0 --- .../Controller/Frontend/NodeController.php | 14 +++++- .../Classes/Domain/Model/EditPreviewMode.php | 43 +++++++++++++++++++ .../Repository/EditPreviewModeRepository.php | 40 +++++++++++++++++ .../FrontendRouting/NodeUriBuilder.php | 12 +++++- .../Override/GlobalCacheIdentifiers.fusion | 2 +- .../Resources/Private/Fusion/RootCase.fusion | 5 +-- 6 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 Neos.Neos/Classes/Domain/Model/EditPreviewMode.php create mode 100644 Neos.Neos/Classes/Domain/Repository/EditPreviewModeRepository.php diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index e37a6601ed3..379472a1118 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -20,6 +20,8 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath; use Neos\ContentRepository\Core\NodeType\NodeTypeConstraintParser; +use Neos\Neos\Domain\Model\EditPreviewMode; +use Neos\Neos\Domain\Repository\EditPreviewModeRepository; use Neos\Neos\FrontendRouting\NodeAddressFactory; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; @@ -110,8 +112,15 @@ class NodeController extends ActionController */ protected $nodeSiteResolvingService; + /** + * @Flow\Inject + * @var EditPreviewModeRepository + */ + protected $editPreviewModeRepository; + /** * @param string $node Legacy name for backwards compatibility of route components + * @param string|null $editPreviewMode Rendering mode like "rawContent" defaults to defaultEditPreviewMode from settings * @throws NodeNotFoundException * @throws \Neos\Flow\Mvc\Exception\StopActionException * @throws \Neos\Flow\Mvc\Exception\UnsupportedRequestTypeException @@ -122,7 +131,7 @@ class NodeController extends ActionController * with unsafe requests from widgets or plugins that are rendered on the node * - For those the CSRF token is validated on the sub-request, so it is safe to be skipped here */ - public function previewAction(string $node): void + public function previewAction(string $node, string $editPreviewMode = null): void { $visibilityConstraints = VisibilityConstraints::frontend(); if ($this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) { @@ -166,6 +175,9 @@ public function previewAction(string $node): void $this->view->assignMultiple([ 'value' => $nodeInstance, 'site' => $site, + 'editPreviewMode' => $editPreviewMode + ? $this->editPreviewModeRepository->findByName($editPreviewMode) + : $this->editPreviewModeRepository->findDefault() ]); if (!$nodeAddress->isInLiveWorkspace()) { diff --git a/Neos.Neos/Classes/Domain/Model/EditPreviewMode.php b/Neos.Neos/Classes/Domain/Model/EditPreviewMode.php new file mode 100644 index 00000000000..7dd7b0d38e2 --- /dev/null +++ b/Neos.Neos/Classes/Domain/Model/EditPreviewMode.php @@ -0,0 +1,43 @@ + + */ + #[Flow\InjectConfiguration(path:"userInterface.editPreviewModes")] + protected array $editPreviewModeConfigurations; + + public function findDefault(): EditPreviewMode + { + return EditPreviewMode::fromNameAndConfiguration($this->defaultEditPreviewMode, $this->editPreviewModeConfigurations[$this->defaultEditPreviewMode]); + } + + public function findByName(string $name): EditPreviewMode + { + return EditPreviewMode::fromNameAndConfiguration($name, $this->editPreviewModeConfigurations[$name]); + } +} diff --git a/Neos.Neos/Classes/FrontendRouting/NodeUriBuilder.php b/Neos.Neos/Classes/FrontendRouting/NodeUriBuilder.php index 3f77257f2a5..a64dfb299f6 100644 --- a/Neos.Neos/Classes/FrontendRouting/NodeUriBuilder.php +++ b/Neos.Neos/Classes/FrontendRouting/NodeUriBuilder.php @@ -80,11 +80,19 @@ public function uriFor(NodeAddress $nodeAddress): UriInterface */ public function previewUriFor(NodeAddress $nodeAddress): UriInterface { - return new Uri($this->uriBuilder->uriFor( + $uri = new Uri($this->uriBuilder->uriFor( 'preview', - ['node' => $nodeAddress->serializeForUri()], + [], 'Frontend\Node', 'Neos.Neos' )); + + $queryParameters = ['node' => $nodeAddress->serializeForUri()]; + + if ($this->uriBuilder->getRequest()->hasArgument('editPreviewMode')) { + $queryParameters['editPreviewMode'] = $this->uriBuilder->getRequest()->getArgument('editPreviewMode'); + } + + return $uri->withQuery(http_build_query($queryParameters)); } } diff --git a/Neos.Neos/Resources/Private/Fusion/Override/GlobalCacheIdentifiers.fusion b/Neos.Neos/Resources/Private/Fusion/Override/GlobalCacheIdentifiers.fusion index 6e5417ac858..cf80fce91af 100644 --- a/Neos.Neos/Resources/Private/Fusion/Override/GlobalCacheIdentifiers.fusion +++ b/Neos.Neos/Resources/Private/Fusion/Override/GlobalCacheIdentifiers.fusion @@ -6,5 +6,5 @@ prototype(Neos.Fusion:GlobalCacheIdentifiers) { workspaceChain = ${Array.join(Array.keys(Neos.Caching.getWorkspaceChain(documentNode)), ',')} workspaceChain.@if.has = ${!!documentNode} - editPreviewMode = ${editPreviewMode} + editPreviewMode = ${editPreviewMode.name} } diff --git a/Neos.Neos/Resources/Private/Fusion/RootCase.fusion b/Neos.Neos/Resources/Private/Fusion/RootCase.fusion index cd1cf2a84f7..3755c3050ce 100644 --- a/Neos.Neos/Resources/Private/Fusion/RootCase.fusion +++ b/Neos.Neos/Resources/Private/Fusion/RootCase.fusion @@ -17,9 +17,8 @@ root { editPreviewMode { @position = 'end 9996' - possibleEditPreviewModePath = ${documentNode.context.currentRenderingMode.fusionPath} - condition = ${Neos.Node.inBackend(documentNode) && this.possibleEditPreviewModePath != null && this.possibleEditPreviewModePath != ''} - renderPath = ${'/' + this.possibleEditPreviewModePath} + condition = ${Neos.Node.inBackend(documentNode) && editPreviewMode.fusionPath} + renderPath = ${'/' + editPreviewMode.fusionPath} } format {