From 1afaf57fd2a4e892667409f4560daab557ced039 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 8 Jan 2025 23:45:43 +0600 Subject: [PATCH] pkp/pkp-lib#10690 Allow to fallback locale for localized data on eloquent model --- classes/core/traits/ModelWithSettings.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/classes/core/traits/ModelWithSettings.php b/classes/core/traits/ModelWithSettings.php index f59ab832a87..36225489f5b 100644 --- a/classes/core/traits/ModelWithSettings.php +++ b/classes/core/traits/ModelWithSettings.php @@ -21,6 +21,7 @@ use Eloquence\Behaviours\HasCamelCasing; use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Casts\Attribute; +use PKP\core\traits\LocalizedData; use PKP\core\casts\MultilingualSettingAttribute; use PKP\core\maps\Schema; use PKP\core\SettingsBuilder; @@ -31,6 +32,7 @@ trait ModelWithSettings { use HasCamelCasing; + use LocalizedData; /** * @see \Illuminate\Database\Eloquent\Concerns\GuardsAttributes::$guardableColumns @@ -131,10 +133,6 @@ public function getMultilingualProps(): array */ public function getLocalizedData(string $data, ?string $locale = null): mixed { - if (is_null($locale)) { - $locale = Locale::getLocale(); - } - if (!in_array($data, $this->getMultilingualProps())) { throw new Exception( sprintf('Given localized property %s does not exist in %s model', $data, static::class) @@ -143,7 +141,7 @@ public function getLocalizedData(string $data, ?string $locale = null): mixed $multilingualProp = $this->getAttribute($data); - return $multilingualProp[$locale] ?? null; + return $this->getBestLocalizedData($multilingualProp, $locale); } /**