function Settings::overriddenSettingByUser
Same name and namespace in other branches
- main core/themes/admin/src/Settings.php \Drupal\admin\Settings::overriddenSettingByUser()
After build callback to modify the description if a setting is overwritten.
Parameters
array $element: A renderable array.
Return value
array The updated renderable array containing the new description.
File
-
core/
themes/ admin/ src/ Settings.php, line 389
Class
- Settings
- Service to handle overridden user settings.
Namespace
Drupal\adminCode
public static function overriddenSettingByUser(array $element) : array {
$settings = self::getInstance();
// Check if this is overridden by the logged in user.
if ($element && isset($element['#name']) && $settings->overridden($element['#name'])) {
$userEditUrl = Url::fromRoute('entity.user.edit_form', [
'user' => \Drupal::currentUser()->id(),
])
->toString();
$value = $settings->get($element['#name']);
if ($element['#type'] === 'radios' || $element['#type'] === 'select') {
$value = $element['#options'][$value];
}
if ($element['#type'] === 'checkbox') {
$value = $value ? t('Enabled') : t('Disabled');
}
$element += [
'#description' => '',
];
$element['#description'] .= '<span class="form-item__warning">' . t('This setting is overridden by the <a href=":editUrl">current user</a>. @title: %value', [
'@title' => $element['#title'],
'%value' => $value,
':editUrl' => $userEditUrl,
]) . '</span>';
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.