function user_form_system_regional_settings_alter

Same name in other branches
  1. 9 core/modules/user/user.module \user_form_system_regional_settings_alter()
  2. 8.9.x core/modules/user/user.module \user_form_system_regional_settings_alter()
  3. 11.x core/modules/user/user.module \user_form_system_regional_settings_alter()

Implements hook_form_FORM_ID_alter() for \Drupal\system\Form\RegionalForm.

File

core/modules/user/user.module, line 1278

Code

function user_form_system_regional_settings_alter(&$form, FormStateInterface $form_state) {
    $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.