2

I want to change the user configurable timezone format on the regional settings and user settings form.

For example, it displays as Asia/Kolkata: Friday, October 9, 2015 - 17:24 +0530 I want to display it as Asia/Kolkata. I have used following code but not working.

function my_modue_form_system_regional_settings_alter(&$form, &$form_state, $form_id) {
dpm(timezone_identifiers_list());
dpm($form);
$form['timezone']['date_default_timezone']['#options'] = timezone_identifiers_list();
}

Is it possible to do this?

1 Answer 1

1

Yes, you're close. The problem with the above code is that it doesn't set the correct key values in #options; thus upon saving, the date_default_timezone variable will be set to some numeric key instead of an accepted PHP timezone string that is expected for the variable.

Do something like this to set the correct key:

function token_form_system_regional_settings_alter(&$form, &$form_state, $form_id) {
  $options = array();
  foreach(timezone_identifiers_list() as $timezone) {
    //$options[$timezone] sets the value for date_default_timezone select
    //$timezone set the display for select
    $options[$timezone] = $timezone;
  }
  $form['timezone']['date_default_timezone']['#options'] = $options;
}
3
  • It is shows only in regional settings form not in user profile form. I have tried same code but not working
    – user50991
    Commented Oct 12, 2015 at 6:37
  • The same code won't work; you'll need to alter $form['timezone']['timezone']['#options'] = $options; if you're talking about the user_profile_form form.
    – Shawn Conn
    Commented Oct 14, 2015 at 20:10
  • It works now @Shawn Conn
    – user50991
    Commented Oct 15, 2015 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.