function system_user_timezone

Add the time zone field to the user edit and register forms.

2 calls to system_user_timezone()

File

drupal/core/modules/system/system.module, line 2447
Configuration system that lets administrators modify the workings of the site.

Code

function system_user_timezone(&$form, &$form_state) {
  global $user;
  $account = $form_state['controller']
    ->getEntity($form_state);
  $form['timezone'] = array(
    '#type' => 'details',
    '#title' => t('Locale settings'),
    '#weight' => 6,
    '#collapsible' => TRUE,
  );
  $form['timezone']['timezone'] = array(
    '#type' => 'select',
    '#title' => t('Time zone'),
    '#default_value' => isset($account->timezone) ? $account->timezone : ($account->uid == $user->uid ? config('system.date')
      ->get('timezone.default') : ''),
    '#options' => system_time_zones($account->uid != $user->uid),
    '#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
  );
  if (!isset($account->timezone) && $account->uid == $user->uid && empty($form_state['input']['timezone'])) {
    $form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.');
    $form['timezone']['timezone']['#attributes'] = array(
      'class' => array(
        'timezone-detect',
      ),
    );
    drupal_add_library('system', 'drupal.timezone');
  }
}