From 9c23336e549f1f7e510f714fdc788832e36b8f09 Mon Sep 17 00:00:00 2001 From: October CMS Date: Sat, 7 Jan 2023 09:48:49 +1100 Subject: [PATCH] Adds multisite support --- components/Post.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/Post.php b/components/Post.php index 8faa8ff..d2437b8 100644 --- a/components/Post.php +++ b/components/Post.php @@ -64,6 +64,22 @@ public function init() return $newParams; }); + + Event::listen('cms.sitePicker.overrideParams', function ($page, $params, $currentSite, $proposedSite) { + $newParams = $params; + $oldLocale = $currentSite->hard_locale; + $newLocale = $proposedSite->hard_locale; + + if (isset($params['slug'])) { + $records = BlogPost::transWhere('slug', $params['slug'], $oldLocale)->first(); + if ($records) { + $records->translateContext($newLocale); + $newParams['slug'] = $records['slug']; + } + } + + return $newParams; + }); } public function onRun()