From eafe146db86fe45dd0667fd36b972437d50e96ae Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Fri, 8 Sep 2023 17:12:29 +0200 Subject: [PATCH 1/5] Feature: Add Status Code to Shortcuts --- .../Controller/Frontend/NodeController.php | 9 ++++++++- .../ContentRepository/Version20230809164806.yaml | 15 +++++++++++++++ Neos.Neos/NodeTypes/Document/Shortcut.yaml | 12 ++++++++++++ .../Translations/en/NodeTypes/Shortcut.xlf | 3 +++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index f529f9f3844..d2b68ad70c4 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -309,7 +309,14 @@ protected function handleShortcutNode(NodeAddress $nodeAddress, ContentRepositor } else { $resolvedUri = $resolvedTarget; } - $this->redirectToUri($resolvedUri); + $subgraph = $contentRepository->getContentGraph()->getSubgraph( + $nodeAddress->contentStreamId, + $nodeAddress->dimensionSpacePoint, + VisibilityConstraints::withoutRestrictions() + ); + $redirectStatusCode = $subgraph->findNodeById($nodeAddress->nodeAggregateId)->getProperty('httpStatusCode'); + + $this->redirectToUri($resolvedUri, statusCode: $redirectStatusCode ?: 303); } private function fillCacheWithContentNodes( diff --git a/Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml b/Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml new file mode 100644 index 00000000000..7aa6be5f61a --- /dev/null +++ b/Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml @@ -0,0 +1,15 @@ +comments: 'Migrate shortcut nodes: add httpStatusCode property' +migration: + - + filters: + - + type: 'NodeType' + settings: + nodeType: 'Neos.Neos:Shortcut' + transformations: + - type: 'AddNewProperty' + settings: + newPropertyName: 'httpStatusCode' + serializedValue: '303' + type: 'int' + diff --git a/Neos.Neos/NodeTypes/Document/Shortcut.yaml b/Neos.Neos/NodeTypes/Document/Shortcut.yaml index 94116d8223e..722168506c3 100644 --- a/Neos.Neos/NodeTypes/Document/Shortcut.yaml +++ b/Neos.Neos/NodeTypes/Document/Shortcut.yaml @@ -46,3 +46,15 @@ setTargetModeIfNotEmpty: property: 'targetMode' handler: 'Neos.Neos/Inspector/Handlers/ShortcutHandler' + + httpStatusCode: + type: int + defaultValue: 303 + ui: + label: i18n + inspector: + # change this to edit the status code in the inspector + hidden: true + group: 'document' + editor: 'Neos.Neos/Inspector/Editors/TextFieldEditor' + diff --git a/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf b/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf index 294dcac151e..0f29110cda4 100644 --- a/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf +++ b/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf @@ -29,6 +29,9 @@ Selected target + + HTTP Redirect status code + From b58d9d1aedca3c03b011144ee7caac7714820e79 Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:22:46 +0200 Subject: [PATCH 2/5] Fix: resolve linting --- Neos.Neos/Classes/Controller/Frontend/NodeController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index d2b68ad70c4..8518ef5f230 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -314,9 +314,9 @@ protected function handleShortcutNode(NodeAddress $nodeAddress, ContentRepositor $nodeAddress->dimensionSpacePoint, VisibilityConstraints::withoutRestrictions() ); - $redirectStatusCode = $subgraph->findNodeById($nodeAddress->nodeAggregateId)->getProperty('httpStatusCode'); + $redirectStatusCode = $subgraph->findNodeById($nodeAddress->nodeAggregateId)?->getProperty('httpStatusCode') ?? 303; - $this->redirectToUri($resolvedUri, statusCode: $redirectStatusCode ?: 303); + $this->redirectToUri($resolvedUri, statusCode: $redirectStatusCode); } private function fillCacheWithContentNodes( From 62bfac81d4be610e8a9d2192979ba421ad303a23 Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:32:48 +0200 Subject: [PATCH 3/5] Fix: Add to testing --- .../Tests/Behavior/Features/FrontendRouting/Shortcuts.feature | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature b/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature index 61959a58a01..8ea1722dcee 100644 --- a/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature +++ b/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature @@ -22,6 +22,8 @@ Feature: Routing behavior of shortcut nodes type: string target: type: string + httpStatusCode: + type: int 'Neos.Neos:Content': [] 'Neos.Neos:Test.Routing.Page': From 2f8140dfdf163c3fdf0d3486086eace54c4b056c Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:12:51 +0100 Subject: [PATCH 4/5] Feature: Use global Setting instead of Node Type property --- .../Controller/Frontend/NodeController.php | 13 +++++-------- .../ContentRepository/Version20230809164806.yaml | 15 --------------- Neos.Neos/NodeTypes/Document/Shortcut.yaml | 12 ------------ .../Translations/en/NodeTypes/Shortcut.xlf | 3 --- .../Features/FrontendRouting/Shortcuts.feature | 2 -- 5 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index c804f124dd1..ff5cdc7ec1b 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -106,6 +106,9 @@ class NodeController extends ActionController #[Flow\Inject] protected RenderingModeService $renderingModeService; + #[Flow\InjectConfiguration(path: "frontend.shortcutRedirectHttpStatusCode", package: "Neos.Neos")] + protected int $shortcutRedirectHttpStatusCode; + /** * @param string $node Legacy name for backwards compatibility of route components * @throws NodeNotFoundException @@ -299,14 +302,8 @@ protected function handleShortcutNode(NodeAddress $nodeAddress, ContentRepositor } else { $resolvedUri = $resolvedTarget; } - $subgraph = $contentRepository->getContentGraph()->getSubgraph( - $nodeAddress->contentStreamId, - $nodeAddress->dimensionSpacePoint, - VisibilityConstraints::withoutRestrictions() - ); - $redirectStatusCode = $subgraph->findNodeById($nodeAddress->nodeAggregateId)?->getProperty('httpStatusCode') ?? 303; - - $this->redirectToUri($resolvedUri, statusCode: $redirectStatusCode); + + $this->redirectToUri($resolvedUri, statusCode: $this->shortcutRedirectHttpStatusCode); } private function fillCacheWithContentNodes( diff --git a/Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml b/Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml deleted file mode 100644 index 7aa6be5f61a..00000000000 --- a/Neos.Neos/Migrations/ContentRepository/Version20230809164806.yaml +++ /dev/null @@ -1,15 +0,0 @@ -comments: 'Migrate shortcut nodes: add httpStatusCode property' -migration: - - - filters: - - - type: 'NodeType' - settings: - nodeType: 'Neos.Neos:Shortcut' - transformations: - - type: 'AddNewProperty' - settings: - newPropertyName: 'httpStatusCode' - serializedValue: '303' - type: 'int' - diff --git a/Neos.Neos/NodeTypes/Document/Shortcut.yaml b/Neos.Neos/NodeTypes/Document/Shortcut.yaml index 722168506c3..94116d8223e 100644 --- a/Neos.Neos/NodeTypes/Document/Shortcut.yaml +++ b/Neos.Neos/NodeTypes/Document/Shortcut.yaml @@ -46,15 +46,3 @@ setTargetModeIfNotEmpty: property: 'targetMode' handler: 'Neos.Neos/Inspector/Handlers/ShortcutHandler' - - httpStatusCode: - type: int - defaultValue: 303 - ui: - label: i18n - inspector: - # change this to edit the status code in the inspector - hidden: true - group: 'document' - editor: 'Neos.Neos/Inspector/Editors/TextFieldEditor' - diff --git a/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf b/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf index 0f29110cda4..294dcac151e 100644 --- a/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf +++ b/Neos.Neos/Resources/Private/Translations/en/NodeTypes/Shortcut.xlf @@ -29,9 +29,6 @@ Selected target - - HTTP Redirect status code - diff --git a/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature b/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature index 0eb0c1c323e..3bba3d61557 100644 --- a/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature +++ b/Neos.Neos/Tests/Behavior/Features/FrontendRouting/Shortcuts.feature @@ -20,8 +20,6 @@ Feature: Routing behavior of shortcut nodes type: string target: type: string - httpStatusCode: - type: int 'Neos.Neos:Content': [] 'Neos.Neos:Test.Routing.Page': From 2d878e043e9509d6ff5c7325e1edaf05a40d0e32 Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:16:21 +0100 Subject: [PATCH 5/5] Feature: Add frontend Shortcut setting in config --- Neos.Neos/Classes/Controller/Frontend/NodeController.php | 2 +- Neos.Neos/Configuration/Settings.yaml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Neos.Neos/Classes/Controller/Frontend/NodeController.php b/Neos.Neos/Classes/Controller/Frontend/NodeController.php index ff5cdc7ec1b..123b33cb39f 100644 --- a/Neos.Neos/Classes/Controller/Frontend/NodeController.php +++ b/Neos.Neos/Classes/Controller/Frontend/NodeController.php @@ -302,7 +302,7 @@ protected function handleShortcutNode(NodeAddress $nodeAddress, ContentRepositor } else { $resolvedUri = $resolvedTarget; } - + $this->redirectToUri($resolvedUri, statusCode: $this->shortcutRedirectHttpStatusCode); } diff --git a/Neos.Neos/Configuration/Settings.yaml b/Neos.Neos/Configuration/Settings.yaml index 4f45714082b..715dc37d895 100755 --- a/Neos.Neos/Configuration/Settings.yaml +++ b/Neos.Neos/Configuration/Settings.yaml @@ -82,6 +82,10 @@ Neos: label: 'Neos.Neos:Main:nodeTypes.groups.plugins' collapsed: true + frontend: + # HTTP Status Code used for redirecting Neos.Neos:Shortcut to target + shortcutRedirectHttpStatusCode: 303 + userInterface: # Switch on to see all translated labels getting scrambled. You now can localize