Score:2

Is there a way to restrict time zone options in the DateTimeRange field widget?

in flag

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?

cn flag
I just added a datetime range widget and it doesn't have timezone settings - maybe you have something like [this](https://www.drupal.org/project/datetime_range_timezone) installed?
Kevin avatar
in flag
It's possible - I'll check it out. It's a new project. Thanks!
Kevin avatar
in flag
Not in the project - perhaps it is something else. Still looking.
cn flag
Try searching for uses of `system_time_zones`, that's probably the most likely function to have been used for the options
Kevin avatar
in flag
The core DateTime element does that for options.
cn flag
I would just use form_alter and remove the options that are not in your preset list.
liquidcms avatar
us flag
Form alter works on a simple date field added to an entity such as on the user profile page; but no luck so far altering this list when it is on a date field in a paragraph.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.