*
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
* Use \Drupal\user\UserInterface::TIMEZONE_DEFAULT instead.
+ *
+ * @see https://www.drupal.org/node/2831620
*/
const DRUPAL_USER_TIMEZONE_DEFAULT = 0;
*
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
* Use \Drupal\user\UserInterface::TIMEZONE_EMPTY instead.
+ *
+ * @see https://www.drupal.org/node/2831620
*/
const DRUPAL_USER_TIMEZONE_EMPTY = 1;
*
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
* Use \Drupal\user\UserInterface::TIMEZONE_SELECT instead.
+ *
+ * @see https://www.drupal.org/node/2831620
*/
const DRUPAL_USER_TIMEZONE_SELECT = 2;
* Use \Drupal\block\BlockRepositoryInterface::REGIONS_VISIBLE instead.
*
* @see system_region_list()
+ * @see https://www.drupal.org/node/2831620
*/
const REGIONS_VISIBLE = 'visible';
* Use \Drupal\block\BlockRepositoryInterface::REGIONS_ALL instead.
*
* @see system_region_list()
+ * @see https://www.drupal.org/node/2831620
*/
const REGIONS_ALL = 'all';
}
// Get the major Drupal version.
- list($version, ) = explode('.', \Drupal::VERSION);
+ list($version,) = explode('.', \Drupal::VERSION);
// Attach default meta tags.
$meta_default = [
'#type' => 'select',
'#title' => t('Time zone'),
'#default_value' => $account->getTimezone() ? $account->getTimezone() : \Drupal::config('system.date')->get('timezone.default'),
- '#options' => system_time_zones($account->id() != $user->id()),
+ '#options' => system_time_zones($account->id() != $user->id(), TRUE),
'#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
];
$user_input = $form_state->getUserInput();
_system_rebuild_module_data_ensure_required($module, $modules);
}
-
if ($profile && isset($modules[$profile])) {
// The installation profile is required, if it's a valid module.
$modules[$profile]->info['required'] = TRUE;
/**
* Generate an array of time zones and their local time&date.
*
- * @param $blank
+ * @param mixed $blank
* If evaluates true, prepend an empty time zone option to the array.
+ * @param bool $grouped
+ * (optional) Whether the timezones should be grouped by region.
+ *
+ * @return array
+ * An array or nested array containing time zones, keyed by the system name.
*/
-function system_time_zones($blank = NULL) {
+function system_time_zones($blank = NULL, $grouped = FALSE) {
$zonelist = timezone_identifiers_list();
$zones = $blank ? ['' => t('- None selected -')] : [];
foreach ($zonelist as $zone) {
}
// Sort the translated time zones alphabetically.
asort($zones);
+ if ($grouped) {
+ $grouped_zones = [];
+ foreach ($zones as $key => $value) {
+ $split = explode('/', $value);
+ $city = array_pop($split);
+ $region = array_shift($split);
+ if (!empty($region)) {
+ $grouped_zones[$region][$key] = empty($split) ? $city : $city . ' (' . implode('/', $split) . ')';
+ }
+ else {
+ $grouped_zones[$key] = $value;
+ }
+ }
+ foreach ($grouped_zones as $key => $value) {
+ if (is_array($grouped_zones[$key])) {
+ asort($grouped_zones[$key]);
+ }
+ }
+ $zones = $grouped_zones;
+ }
+
return $zones;
}