function UserHooks::formSystemRegionalSettingsAlter
Implements hook_form_FORM_ID_alter() for \Drupal\system\Form\RegionalForm.
File
-
core/
modules/ user/ src/ Hook/ UserHooks.php, line 439
Class
- UserHooks
- Hook implementations for user.
Namespace
Drupal\user\HookCode
public function formSystemRegionalSettingsAlter(&$form, FormStateInterface $form_state) : void {
$config = \Drupal::config('system.date');
$form['timezone']['configurable_timezones'] = [
'#type' => 'checkbox',
'#title' => t('Users may set their own time zone'),
'#default_value' => $config->get('timezone.user.configurable'),
];
$form['timezone']['configurable_timezones_wrapper'] = [
'#type' => 'container',
'#states' => [
// Hide the user configured timezone settings when users are forced to use
// the default setting.
'invisible' => [
'input[name="configurable_timezones"]' => [
'checked' => FALSE,
],
],
],
];
$form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = [
'#type' => 'checkbox',
'#title' => t('Remind users at login if their time zone is not set'),
'#default_value' => $config->get('timezone.user.warn'),
'#description' => t('Only applied if users may set their own time zone.'),
];
$form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = [
'#type' => 'radios',
'#title' => t('Time zone for new users'),
'#default_value' => $config->get('timezone.user.default'),
'#options' => [
UserInterface::TIMEZONE_DEFAULT => t('Default time zone'),
UserInterface::TIMEZONE_EMPTY => t('Empty time zone'),
UserInterface::TIMEZONE_SELECT => t('Users may set their own time zone at registration'),
],
'#description' => t('Only applied if users may set their own time zone.'),
];
$form['#submit'][] = 'user_form_system_regional_settings_submit';
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.