From 70d21791135ac43d50a75134a4e5c0184526e9af Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Fri, 15 Sep 2023 20:43:19 +0200 Subject: [PATCH 1/4] TASK: Introduce constant `RenderingMode::FRONTEND` for system integrated rendering mode --- .../Controller/Frontend/NodeController.php | 3 ++- .../Classes/Domain/Model/RenderingMode.php | 17 +++++++++++++---- .../Domain/Service/RenderingModeService.php | 4 ++-- Neos.Neos/Classes/View/FusionExceptionView.php | 3 ++- Neos.Neos/Classes/View/FusionView.php | 3 ++- Neos.Neos/Configuration/Settings.yaml | 3 ++- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index c8e776c035f..26571bf01c4 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -35,6 +35,7 @@ use Neos\Flow\Security\Context as SecurityContext; use Neos\Flow\Session\SessionInterface; use Neos\Flow\Utility\Now; +use Neos\Neos\Domain\Model\RenderingMode; use Neos\Neos\Domain\Service\NodeSiteResolvingService; use Neos\Neos\Domain\Service\RenderingModeService; use Neos\Neos\FrontendRouting\Exception\InvalidShortcutException; @@ -247,7 +248,7 @@ public function showAction(string $node, bool $showInvisible = false): void $this->handleShortcutNode($nodeAddress, $contentRepository); } - $this->view->setOption('renderingModeName', 'frontend'); + $this->view->setOption('renderingModeName', RenderingMode::FRONTEND); $this->view->assignMultiple([ 'value' => $nodeInstance, diff --git a/Neos.Neos/Classes/Domain/Model/RenderingMode.php b/Neos.Neos/Classes/Domain/Model/RenderingMode.php index 19a78934b73..389f23c1f2f 100644 --- a/Neos.Neos/Classes/Domain/Model/RenderingMode.php +++ b/Neos.Neos/Classes/Domain/Model/RenderingMode.php @@ -14,7 +14,7 @@ namespace Neos\Neos\Domain\Model; -use Neos\Utility\ObjectAccess; +use Neos\Neos\Domain\Exception; /** * Describes the mode in which the Neos interface is rendering currently, @@ -22,6 +22,8 @@ */ class RenderingMode { + public const FRONTEND = 'frontend'; + /** * @param array $options */ @@ -36,13 +38,20 @@ public function __construct( } /** - * Creates an UserInterfaceMode object by configuration + * Creates a rendering mode from its configuration * * @param string $modeName * @param array $configuration */ public static function createFromConfiguration(string $modeName, array $configuration): RenderingMode { + if ($modeName === RenderingMode::FRONTEND) { + throw new Exception( + 'Cannot instantiate system rendering mode "frontend" from configuration.' + . ' Please use RenderingMode::createFrontend().', + 1694802951840 + ); + } $mode = new RenderingMode( $modeName, $configuration['isEditingMode'] ?? false, @@ -55,12 +64,12 @@ public static function createFromConfiguration(string $modeName, array $configur } /** - * Creates the live User interface mode + * Creates the system integrated rendering mode 'frontend' */ public static function createFrontend(): RenderingMode { return new RenderingMode( - 'frontend', + RenderingMode::FRONTEND, false, false, 'Frontend', diff --git a/Neos.Neos/Classes/Domain/Service/RenderingModeService.php b/Neos.Neos/Classes/Domain/Service/RenderingModeService.php index c4735309552..296362aaf4c 100644 --- a/Neos.Neos/Classes/Domain/Service/RenderingModeService.php +++ b/Neos.Neos/Classes/Domain/Service/RenderingModeService.php @@ -85,14 +85,14 @@ public function findDefault(): RenderingMode */ public function findByName(string $modeName): RenderingMode { - if ($modeName === 'frontend') { + if ($modeName === RenderingMode::FRONTEND) { return RenderingMode::createFrontend(); } if (isset($this->editPreviewModes[$modeName])) { return RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]); } throw new Exception( - 'The requested interface render mode "' . $modeName . '" is not configured.' + 'The requested rendering mode "' . $modeName . '" is not configured.' . ' Please make sure it exists as key in the Settings path "Neos.Neos.Interface.editPreviewModes".', 1427715962 ); diff --git a/Neos.Neos/Classes/View/FusionExceptionView.php b/Neos.Neos/Classes/View/FusionExceptionView.php index 38e56f23d6b..5176990ff4b 100644 --- a/Neos.Neos/Classes/View/FusionExceptionView.php +++ b/Neos.Neos/Classes/View/FusionExceptionView.php @@ -35,6 +35,7 @@ use Neos\Fusion\Core\Runtime as FusionRuntime; use Neos\Fusion\Core\RuntimeFactory; use Neos\Fusion\Exception\RuntimeException; +use Neos\Neos\Domain\Model\RenderingMode; use Neos\Neos\Domain\Repository\SiteRepository; use Neos\Neos\Domain\Service\FusionService; use Neos\Neos\Domain\Service\SiteNodeUtility; @@ -204,7 +205,7 @@ protected function getFusionRuntime( $fusionGlobals = FusionGlobals::fromArray([ 'request' => $this->controllerContext->getRequest(), - 'renderingModeName' => 'frontend' + 'renderingModeName' => RenderingMode::FRONTEND ]); $this->fusionRuntime = $this->runtimeFactory->createFromConfiguration( $fusionConfiguration, diff --git a/Neos.Neos/Classes/View/FusionView.php b/Neos.Neos/Classes/View/FusionView.php index ba06676b7af..e9c2ba43ab7 100644 --- a/Neos.Neos/Classes/View/FusionView.php +++ b/Neos.Neos/Classes/View/FusionView.php @@ -24,6 +24,7 @@ use Neos\Fusion\Core\Runtime; use Neos\Fusion\Core\RuntimeFactory; use Neos\Fusion\Exception\RuntimeException; +use Neos\Neos\Domain\Model\RenderingMode; use Neos\Neos\Domain\Repository\SiteRepository; use Neos\Neos\Domain\Service\FusionService; use Neos\Neos\Domain\Service\SiteNodeUtility; @@ -102,7 +103,7 @@ public function render(): string|ResponseInterface 'boolean' ], 'renderingModeName' => [ - 'frontend', + RenderingMode::FRONTEND, 'Name of the user interface mode to use', 'string' ] diff --git a/Neos.Neos/Configuration/Settings.yaml b/Neos.Neos/Configuration/Settings.yaml index 32117df22fc..16a96abe01f 100755 --- a/Neos.Neos/Configuration/Settings.yaml +++ b/Neos.Neos/Configuration/Settings.yaml @@ -271,7 +271,8 @@ Neos: defaultEditPreviewMode: inPlace editPreviewModes: - # the "frontend" renderingMode is hardcoded internally and cannot be modified + # the system integrated rendering mode "frontend" cannot be configured + # frontend: {} inPlace: isEditingMode: true isPreviewMode: false From e2c6f5e27c9690611fc0c562c648a0f9c335a87e Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Fri, 15 Sep 2023 20:47:11 +0200 Subject: [PATCH 2/4] TASK: RenderingModeService instances runtime cache --- .../Domain/Service/RenderingModeService.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Neos.Neos/Classes/Domain/Service/RenderingModeService.php b/Neos.Neos/Classes/Domain/Service/RenderingModeService.php index 296362aaf4c..9930e4d26aa 100644 --- a/Neos.Neos/Classes/Domain/Service/RenderingModeService.php +++ b/Neos.Neos/Classes/Domain/Service/RenderingModeService.php @@ -51,6 +51,11 @@ class RenderingModeService */ protected $defaultEditPreviewMode; + /** + * @var array + */ + private array $instances = []; + /** * Get the current rendering mode. * Will return a live mode when not in backend. @@ -85,16 +90,14 @@ public function findDefault(): RenderingMode */ public function findByName(string $modeName): RenderingMode { - if ($modeName === RenderingMode::FRONTEND) { - return RenderingMode::createFrontend(); - } - if (isset($this->editPreviewModes[$modeName])) { - return RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]); - } - throw new Exception( - 'The requested rendering mode "' . $modeName . '" is not configured.' + return $this->instances[$modeName] ??= match (true) { + $modeName === RenderingMode::FRONTEND => RenderingMode::createFrontend(), + isset($this->editPreviewModes[$modeName]) => RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]), + default => throw new Exception( + 'The requested rendering mode "' . $modeName . '" is not configured.' . ' Please make sure it exists as key in the Settings path "Neos.Neos.Interface.editPreviewModes".', - 1427715962 - ); + 1427715962 + ) + }; } } From 0463da99b0e8128ba1090ee77bcb325fff271dcb Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Fri, 15 Sep 2023 20:53:02 +0200 Subject: [PATCH 3/4] TASK: Remove half-baked solution of session independent preview's Otherwise, this feature would only work for this one page, successive links will currently not have that query param added - the linking service still needs to learn this, but we delay this for another time. --- .../Classes/Controller/Frontend/NodeController.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index 26571bf01c4..d7ef5446465 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -115,7 +115,6 @@ class NodeController extends ActionController /** * @param string $node Legacy name for backwards compatibility of route components - * @param string $renderingModeName Name of the user interface mode to use * @throws NodeNotFoundException * @throws \Neos\Flow\Mvc\Exception\StopActionException * @throws \Neos\Flow\Mvc\Exception\UnsupportedRequestTypeException @@ -126,13 +125,10 @@ 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, string $renderingModeName = null): void + public function previewAction(string $node): void { - if (is_null($renderingModeName)) { - $renderingMode = $this->renderingModeService->findByCurrentUser(); - } else { - $renderingMode = $this->renderingModeService->findByName($renderingModeName); - } + // @todo add $renderingModeName as parameter and append it for successive links again as get parameter to node uris + $renderingMode = $this->renderingModeService->findByCurrentUser(); $visibilityConstraints = VisibilityConstraints::frontend(); if ($this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) { From 5639b6b716a23bac478b9dc50b008ef6537974fc Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Sat, 16 Sep 2023 16:41:12 +0200 Subject: [PATCH 4/4] TASK: Optimize runtime cache for RenderingModes for readability --- .../Domain/Service/RenderingModeService.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Neos.Neos/Classes/Domain/Service/RenderingModeService.php b/Neos.Neos/Classes/Domain/Service/RenderingModeService.php index 9930e4d26aa..5f63b9f313b 100644 --- a/Neos.Neos/Classes/Domain/Service/RenderingModeService.php +++ b/Neos.Neos/Classes/Domain/Service/RenderingModeService.php @@ -90,14 +90,20 @@ public function findDefault(): RenderingMode */ public function findByName(string $modeName): RenderingMode { - return $this->instances[$modeName] ??= match (true) { - $modeName === RenderingMode::FRONTEND => RenderingMode::createFrontend(), - isset($this->editPreviewModes[$modeName]) => RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]), - default => throw new Exception( + if ($instance = $this->instances[$modeName] ?? null) { + return $instance; + } + if ($modeName === RenderingMode::FRONTEND) { + $this->instances[$modeName] = RenderingMode::createFrontend(); + } elseif (isset($this->editPreviewModes[$modeName])) { + $this->instances[$modeName] = RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]); + } else { + throw new Exception( 'The requested rendering mode "' . $modeName . '" is not configured.' . ' Please make sure it exists as key in the Settings path "Neos.Neos.Interface.editPreviewModes".', 1427715962 - ) - }; + ); + } + return $this->instances[$modeName]; } }