Skip to content

Commit

Permalink
pkp#10690 Allow to fallback locale for localized data on eloquent model
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jan 8, 2025
1 parent d15e998 commit 1afaf57
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions classes/core/traits/ModelWithSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
trait ModelWithSettings
{
use HasCamelCasing;
use LocalizedData;

/**
* @see \Illuminate\Database\Eloquent\Concerns\GuardsAttributes::$guardableColumns
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 1afaf57

Please sign in to comment.