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()