diff --git a/Classes/Fusion/Eel/Helper/LocaleHelper.php b/Classes/Fusion/Eel/Helper/LocaleHelper.php new file mode 100644 index 0000000..52a0a10 --- /dev/null +++ b/Classes/Fusion/Eel/Helper/LocaleHelper.php @@ -0,0 +1,59 @@ +getContext()->getDimensions(); + if (array_key_exists($languageDimensionName, $dimensions) && $dimensions[$languageDimensionName] !== []) { + $currentLocale = new Locale($dimensions[$languageDimensionName][0]); + $this->i18nService->getConfiguration()->setCurrentLocale($currentLocale); + $this->i18nService->getConfiguration()->setFallbackRule(['strict' => false, 'order' => array_reverse($dimensions[$languageDimensionName])]); + } + + return $node; + } + + /** + * All methods are considered safe + * + * @param string $methodName + * @return boolean + */ + public function allowsCallOfMethod($methodName) + { + return true; + } +} diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 9b6bd33..f57d7cf 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -2,6 +2,7 @@ Neos: Fusion: defaultContext: NotFound.Context: MOC\NotFound\Fusion\Eel\Helper\ContextHelper + NotFound.LocaleHelper: MOC\NotFound\Fusion\Eel\Helper\LocaleHelper Neos: fusion: autoInclude: @@ -9,3 +10,4 @@ Neos: MOC: NotFound: uriPathSegment: 404 + languageDimensionName: language \ No newline at end of file diff --git a/README.md b/README.md index 42ccd34..b46583b 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,16 @@ Introduction Neos CMS package that loads a normal editable page for displaying a 404 error. -Compatible with Neos 4.3 - 5.x +Compatible with Neos 8.x Supports multiple content dimensions with URI segments and empty segments for default dimensions. Installation ------------ -```composer require "moc/notfound:^4.0"``` +```composer require "moc/notfound"``` Create a page with the URI segment "404" in the root of your site. If using content dimensions with URI segments, -ensure a page exists in all contexts or through fallbacks. +ensure a page exists in all contexts or through fallbacks. Per default the package assumes the name of the language dimension as "language". Alternatively set the following configuration in ``Settings.yaml``: @@ -28,6 +28,7 @@ Alternatively set the following configuration in ``Settings.yaml``: MOC: NotFound: uriPathSegment: 404 + languageDimensionName: language ``` Note: If you override the configuration in a package's configuration instead of globally, you need to ensure that package is loaded after this package. To do so, add ``"moc/notfound": "*"`` to the package's ``require`` section in it's ``composer.json``. diff --git a/Resources/Private/Fusion/Root.fusion b/Resources/Private/Fusion/Root.fusion index c15f6d9..bf16e5c 100644 --- a/Resources/Private/Fusion/Root.fusion +++ b/Resources/Private/Fusion/Root.fusion @@ -14,9 +14,12 @@ error { @position = 'start' condition = ${statusCode >= 400 && statusCode < 500 && notfoundDocument} renderer = Neos.Fusion:Renderer { + languageDimensionName = ${Configuration.setting('MOC.NotFound.languageDimensionName')} + @context.i18nServiceToProperLocale = ${NotFound.LocaleHelper.setCurrentFromNode(notfoundDocument, this.languageDimensionName)} + @context.site = ${notfoundDocument.context.currentSiteNode} @context.node = ${notfoundDocument} @context.documentNode = ${notfoundDocument} renderPath = '/root' } } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index ebaf4b5..d1e98f3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "neos/neos": ">=4.3" + "neos/neos": ">=8.0" }, "autoload": { "psr-4": {