- π¬π§United Kingdom c_archer Cumbria
Patch from #296 does not apply agains Drupal 9.5.7
- π¨π¦Canada joseph.olstad
I suggest simplifying this to allow contrib to handle this.
Add a new hook to alter the list of time zones.
This works quite well and has been in use for a while without telling anyone.
Here in Canada for intranet sites we restrict the timezone selection down to 5 Canadian timezones.
Using this hook invoke and an implements hook for example:
/** * Implements hook_timezone_list_alter($zones). */ function mymodule_timezone_list_alter($zones) { // Don't modify in Views UI $route_match = \Drupal::routeMatch(); if ($route_match->getRouteName() == 'views_ui.form_handler') { return $zones; } $keep = [ 'Rocky Mountain House' => t('Mountain time'), 'Cape Breton' => t('Atlantic time') , 'St Johns' => t('Newfoundland time'), 'Mississauga' => t('Eastern time'), 'Salmon arm' => t('Pacific time'), 'Brandon' => t('Central time'), ]; foreach ($zones as $optgroup => &$group) { if ($optgroup != 'America') { unset($zones[$optgroup]); } else { foreach ($zones['America'] as $index => $option) { if (!in_array($option, array_keys($keep))) { unset($zones['America'][$index]); } else { $zones['America'][$index] .= ' (' . $keep[$option] . ')'; } } } } return $zones; }
I imagine someone is going to suggest extending the TimeZoneFormHelper class and overriding the getOptionsListByRegion method instead?
Is there some Drupal 10 documentation for this sort of thing with examples if for say we wanted to adopt this approach in a contrib module?
I think this should be a contrib solution.
- π¨π¦Canada joseph.olstad
This has been open 9 years, we should probably just leave this to contrib. With that said, given my example provided in comment #305, what is the highest performance /most practical way to handle this case?
- π¨π¦Canada joseph.olstad
- last update
8 months ago Patch Failed to Apply