2

In Drupal 7 I have a date field in a content type that has the Time zone handling option set to "Date's time zone". Setting this option will render a drop down list of time zones in your date field.

I am trying to replace the list of core time zones with a smaller list for just the United States. I found this post which works perfectly for overriding the timezone drop down list on the user profile page. However, I have not been able to figure out how to get a reference to the timezone select list on a date field.

The timezone reference on the user profile field is:

 $form['timezone']['timezone']['#options']

If you print the $form variable to the screen you can clearly see the time zones in the above reference.

What I can't figure out is where the timezone options are in the form variable for a date field. I would expect them to be in somewhere in

 $form['field_event_dates']['und'][0]

I do see a default value for the timezone at

 $form['field_event_dates']['und'][0]['#default_value']['timezone']

but I can't find "options" in there.

Any ideas where the "options" for the time zone are set in the form variable?

1 Answer 1

3

Use hook_date_timezone_process_alter in your custom module to do the magic, see below example and adapat if for you needs

function MODULENAME_date_timezone_process_alter(&$element, &$form_state, $context) {
  // add some logic here
  // keep only the needed values
  // dsm($element['timezone']['#options']);
  $element['timezone']['#options'] = array(
    'Africa/Abidjan ' => 'Africa/Abidjan',
    'America/Detroit' => 'America/Detroit',
  );
}
1
  • of course you will have to add all the american zones, my code is just a sample of how you would do it. you might come up with a function to eliminate from the array the ones which dont start with "America/..." some preg_match or something
    – Victor
    Oct 23, 2013 at 19:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.