function FormHooks::formUserFormAlter
Same name and namespace in other branches
- 11.x core/themes/admin/src/Hook/FormHooks.php \Drupal\admin\Hook\FormHooks::formUserFormAlter()
Implements form_user_form_alter().
Attributes
#[Hook('form_user_form_alter')]
File
-
core/
themes/ admin/ src/ Hook/ FormHooks.php, line 437
Class
- FormHooks
- Provides form related hook implementations.
Namespace
Drupal\admin\HookCode
public function formUserFormAlter(array &$form, FormStateInterface $form_state) : void {
// If new user account, don't show settings yet.
$formObject = $form_state->getFormObject();
if ($formObject instanceof EntityFormInterface && $formObject->getEntity()
->isNew()) {
return;
}
if (Settings::getInstance()->allowUserOverrides()) {
// Inject the settings for the dark mode feature.
$form['admin_theme_settings'] = [
'#type' => 'details',
'#title' => $this->t('Admin theme settings'),
'#open' => TRUE,
'#weight' => 90,
];
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = $form_state->getBuildInfo()['callback_object']
->getEntity();
$form['admin_theme_settings']['enable_user_settings'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable overrides'),
'#description' => $this->t("Enables default admin theme overrides."),
'#default_value' => Settings::getInstance()->userOverrideEnabled($account),
'#weight' => 0,
];
$form['admin_theme_settings']['user_settings'] = [
'#type' => 'container',
'#states' => [
// Show if met.
'visible' => [
':input[name="enable_user_settings"]' => [
'checked' => TRUE,
],
],
],
] + Settings::getInstance()->getSettingsForm($account);
// Attach custom library.
$form['#attached']['library'][] = 'admin/settings';
array_unshift($form['actions']['submit']['#submit'], [
__CLASS__,
'userFormSubmit',
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.