From 1ba35f0bc3978787b56f8b8f7c66ad7aeb617df5 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 4 Mar 2021 15:12:57 +0200 Subject: [PATCH] Fixed missing `Flex Pages` in site if multi-language support has been enabled --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Pages.php | 29 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50777cf68..f9066f2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ 1. [](#bugfix) * Fixed clockwork error when clearing cache * Fixed missing method `translated()` in `Flex Pages` + * Fixed missing `Flex Pages` in site if multi-language support has been enabled # v1.7.7 ## 02/23/2021 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 0c430fd5d..a04cc7890 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -769,6 +769,9 @@ class Pages public function get($path) { $path = (string)$path; + if ($path === '') { + return null; + } // Check for local instances first. if (array_key_exists($path, $this->instances)) { @@ -777,14 +780,26 @@ class Pages $instance = $this->index[$path] ?? null; if (is_string($instance)) { - /** @var Language $language */ - $language = $this->grav['language']; - $lang = $language->getActive(); - if ($lang) { - $instance .= ':' . $lang; + if ($this->directory) { + /** @var Language $language */ + $language = $this->grav['language']; + $lang = $language->getActive(); + if ($lang) { + $languages = $language->getFallbackLanguages($lang, true); + $key = $instance; + $instance = null; + foreach ($languages as $code) { + $test = $code ? $key . ':' . $code : $key; + if (($instance = $this->directory->getObject($test, 'flex_key')) !== null) { + break; + } + } + } else { + $instance = $this->directory->getObject($instance, 'flex_key'); + } } - $instance = $this->directory ? $this->directory->getObject($instance, 'flex_key') : null; - if ($instance) { + + if ($instance instanceof PageInterface) { if ($this->fire_events && method_exists($instance, 'initialize')) { $instance->initialize(); }