Skip to content

Commit

Permalink
#10616 Add ThemePlugin function to get localized theme option value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWr authored Dec 5, 2024
1 parent 1a8ca71 commit 137bd0e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions classes/plugins/ThemePlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,32 @@ public function getOption($name) {
return isset($option->default) ? $option->default : null;
}

/**
* Get the localized value of an option
*
* Modelled on DataObject::getLocalizedData()
*
* @param string $name The name of the option
*/
public function getLocalizedOption($name)
{
$value = $this->getOption($name);

if (!is_array($value)) {
return null;
}

$localePrecedence = AppLocale::getLocalePrecedence();
foreach ($localePrecedence as $localeKey) {
if (is_array($value) && !empty($value[$localeKey])) {
return $value[$localeKey];
}
}

// Fallback: Get the first available piece of data
return $value[array_key_first($value)];
}

/**
* Get an option's configuration settings
*
Expand Down

0 comments on commit 137bd0e

Please sign in to comment.