2

We are using the Date module that allows for enabling of Timezone during node edit (node/edit). We noticed that the dropdown is really long and we were wondering if there was a way to shorten the list to just say ETC, PST, UTC, GMT, etc.

We tried all the configuration setting, but could not shorten the drop down.

Current scenario:

enter image description here

Desired scenario:

Timezone (as an example) - UTC - PST/PDT - MST/MDT - EST/EDT - GMT

1 Answer 1

1

The Date module's field elements are supplied by the Date API module. The timezone component is supplied by its process callback date_timezone_element_process().

It triggers hook_date_timezone_process_alter() which can be evoked by a custom module to alter the options within $element['timezone']['#options'].

For example:

/**
 * Implements hook_date_timezone_process_alter().
 */
function MYMODULE_date_timezone_process_alter(&$element, &$form_state, &$context) {

  if (isset($element['timezone']['#options'])) {
    // @TODO: Supply an array filter function that filters
    // IANA TZ names that don't correspond to
    // UTC - PST/PDT - MST/MDT - EST/EDT - GMT

    // Example: Filter TZ's that are only in the Americas
    $element['timezone']['#options'] = array_filter($element['timezone']['#options'], function($key) {
      return strpos($key, 'America/') !== FALSE;
    }, ARRAY_FILTER_USE_KEY);

  }
}
2
  • The main issue we are having is that the time zone dropdown list does not show any of the values that we need. There are no MST, EST, GMT, etc and we cannot find another option for this. Would this hook alter be able to help use to ensure that when the node is saved with that time zone (assuming we can limit it to what we want) that the correct time zone is displayed on the node view? Oct 19, 2016 at 19:45
  • The hook exposes the data structures used to build the TZ form component and present it to the user. It doesn't have a say in validation (on form submission), or presentation (on node view). The best thing it can do is prevent invalid data from being an option.
    – Shawn Conn
    Oct 19, 2016 at 20:15

Your Answer

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

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