From 7cfe36682a3b4e615cdfdb81dfd957f39601bc0a Mon Sep 17 00:00:00 2001 From: pascalmoser Date: Mon, 17 Oct 2022 16:36:33 +0200 Subject: [PATCH 1/2] build i18n context if document is a fallback document fix #105 --- src/I18nBundle/EventListener/I18nStartupListener.php | 3 ++- src/I18nBundle/Resolver/PimcoreDocumentResolver.php | 9 +++++++++ .../Resolver/PimcoreDocumentResolverInterface.php | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/I18nBundle/EventListener/I18nStartupListener.php b/src/I18nBundle/EventListener/I18nStartupListener.php index dfb8a80..55c4804 100644 --- a/src/I18nBundle/EventListener/I18nStartupListener.php +++ b/src/I18nBundle/EventListener/I18nStartupListener.php @@ -73,7 +73,8 @@ public function onKernelRequest(RequestEvent $event): void return; } - if ($document instanceof Document\Link) { + if ($document instanceof Document\Link && !$this->pimcoreDocumentResolver->isFallbackDocument($document)) { + // only skip context building if the *requested* document is a link return; } diff --git a/src/I18nBundle/Resolver/PimcoreDocumentResolver.php b/src/I18nBundle/Resolver/PimcoreDocumentResolver.php index 1d98b05..cb4482d 100644 --- a/src/I18nBundle/Resolver/PimcoreDocumentResolver.php +++ b/src/I18nBundle/Resolver/PimcoreDocumentResolver.php @@ -45,6 +45,15 @@ public function getDocument(Request $request): ?Document return $this->findFallback($request); } + public function isFallbackDocument(Document $document): bool + { + if (!$this->nearestDocument instanceof Document) { + return false; + } + + return $this->nearestDocument->getId() === $document->getId(); + } + protected function findFallback(Request $request): ?Document { if (!$this->requestHelper->matchesDefaultPimcoreContext($request)) { diff --git a/src/I18nBundle/Resolver/PimcoreDocumentResolverInterface.php b/src/I18nBundle/Resolver/PimcoreDocumentResolverInterface.php index ff32c5c..d88cbb5 100644 --- a/src/I18nBundle/Resolver/PimcoreDocumentResolverInterface.php +++ b/src/I18nBundle/Resolver/PimcoreDocumentResolverInterface.php @@ -8,4 +8,6 @@ interface PimcoreDocumentResolverInterface { public function getDocument(Request $request): ?Document; + + public function isFallbackDocument(Document $document): bool; } From f789f9bbd8f111ad373bf3c64de3c972b3e415da Mon Sep 17 00:00:00 2001 From: pascalmoser Date: Mon, 17 Oct 2022 16:41:04 +0200 Subject: [PATCH 2/2] update UPGRADE.md --- UPGRADE.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 7bb6888..d2dd639 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,8 @@ # Upgrade Notes +## 4.1.0 +- [BUGFIX] I18nContext is missing in static routes if fallback document is an instance of Document\Link [#105](https://github.com/dachcom-digital/pimcore-i18n/issues/105) + ## 4.0.5 - [BUGFIX] Wrong Error Page in Static Route Context [@Zodiarc](https://github.com/dachcom-digital/pimcore-i18n/issues/96) - [BUGFIX] Properly overriding Pimcore ResponseExceptionListener and multisite error page [@Zodiarc](https://github.com/dachcom-digital/pimcore-i18n/pull/101) @@ -98,4 +101,4 @@ i18n: *** -I18nBundle 3.x Upgrade Notes: https://github.com/dachcom-digital/pimcore-i18n/blob/3.x/UPGRADE.md \ No newline at end of file +I18nBundle 3.x Upgrade Notes: https://github.com/dachcom-digital/pimcore-i18n/blob/3.x/UPGRADE.md