2

Is there a way to limit the options of the timezone field in the datetime or datetime range widget in Drupal 8? It currently shows tons of timezones, but we really only need about 10 options. I checked the default widget but did not see anything about how it was building that part of the widget form.

The core DateTime element appears to do:

$element['timezone'] = [
        '#type' => 'select',
        '#options' => system_time_zones(FALSE, TRUE),
        // Default to user's time zone.
        '#default_value' => $element['#date_timezone'],
        '#required' => $element['#required'],
      ];

I guess the only way is to alter this element and configure the timezones that should be selectable?

6
  • 1
    I just added a datetime range widget and it doesn't have timezone settings - maybe you have something like this installed?
    – Clive
    Oct 7 at 20:13
  • It's possible - I'll check it out. It's a new project. Thanks!
    – Kevin
    Oct 8 at 0:02
  • Not in the project - perhaps it is something else. Still looking.
    – Kevin
    Oct 8 at 0:13
  • Try searching for uses of system_time_zones, that's probably the most likely function to have been used for the options
    – Clive
    Oct 8 at 0:56
  • 1
    I would just use form_alter and remove the options that are not in your preset list. Oct 8 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.