From 596ba579d1086a384c9b218ff476cb4a0c398c03 Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Tue, 16 Jul 2019 16:52:51 +0200 Subject: [PATCH] Fix problem with PageData get() function not returning correct data when current translation value is null. WIP #2738 @1 --- src/app/Magic/PageData.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/Magic/PageData.php b/src/app/Magic/PageData.php index f00d4b6..dc8a229 100644 --- a/src/app/Magic/PageData.php +++ b/src/app/Magic/PageData.php @@ -84,10 +84,18 @@ class PageData implements \ArrayAccess public function get($offset, $default = null) { $res = Arr::get($this->_data, $offset, $default); - if (is_array($res) && isset($res[App::getLocale()])) { + + // Get the translated value if the array contains a key matching the locale. + // We have to check if the key exists because the actual value may be null. + // Using isset() on the locale key would give a false negative if the value is null. + if (is_array($res) && array_key_exists(App::getLocale(), $res)) { $res = $res[App::getLocale()]; } + if (!$res) { + return $default; + } + return $res; } -- 2.39.5