From 7e1a9d4b1d92bdc82c7dd09f691162934104c27b Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 31 Jul 2020 00:48:18 -0400 Subject: [PATCH] Prevent problems for URL params that do not exist in Post model (#514) --- components/Post.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/Post.php b/components/Post.php index 34da7a5..b162897 100644 --- a/components/Post.php +++ b/components/Post.php @@ -54,14 +54,14 @@ public function init() Event::listen('translate.localePicker.translateParams', function ($page, $params, $oldLocale, $newLocale) { $newParams = $params; - foreach ($params as $paramName => $paramValue) { - $records = BlogPost::transWhere($paramName, $paramValue, $oldLocale)->first(); - + if (isset($params['slug'])) { + $records = BlogPost::transWhere('slug', $params['slug'], $oldLocale)->first(); if ($records) { $records->translateContext($newLocale); - $newParams[$paramName] = $records[$paramName]; + $newParams['slug'] = $records['slug']; } } + return $newParams; }); }