From 59eb3b4cb2cf16de83f31a1bd66a8f6ab2f3564c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 6 Sep 2019 21:43:43 +0300 Subject: [PATCH] Flex Pages: Quick and dirty multi-language support in frontend --- system/src/Grav/Common/Page/Pages.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index c819d2443..1b2209da7 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -702,6 +702,7 @@ class Pages $instance = $this->instances[(string)$path] ?? null; if (\is_string($instance)) { $instance = $this->flex ? $this->flex->getObject($instance) : null; + $instance = $instance->hasTranslation() ? $instance->getTranslation() : $instance; } if ($instance && !$instance instanceof PageInterface) { throw new \RuntimeException('Routing failed on unknown type', 500); @@ -1323,13 +1324,20 @@ class Pages } $path = $page->path(); - if ($path === $root_path) { + + // FIXME: We really need to do better than this. + if ($page->hasTranslation()) { + $translated = $page->getTranslation(); + } + + if (!$translated || $path === $root_path) { continue; } $parent = dirname($path); $instances[$path] = $page->getFlexKey(); - $children[$parent][$path] = ['slug' => $page->slug()]; + // FIXME: ... better... + $children[$parent][$path] = ['slug' => $translated->slug()]; if (!isset($children[$path])) { $children[$path] = []; }