function TimeZoneFormHelper::getOptionsListByRegion

Same name in other branches
  1. 10 core/lib/Drupal/Core/Datetime/TimeZoneFormHelper.php \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsListByRegion()

Generate an array of time zones names grouped by region.

This method retrieves the list of IANA time zones names that PHP is configured to use, for display to users. It does not return the backward compatible names (i.e., the ones defined in the back-zone file).

Parameters

bool $blank: (optional) If TRUE, prepend an empty time zone option to the array.

Return value

array An nested array containing time zones, keyed by the system name. The keys are valid time zone identifiers provided by \DateTimeZone::listIdentifiers()

8 calls to TimeZoneFormHelper::getOptionsListByRegion()
AccountForm::form in core/modules/user/src/AccountForm.php
Gets the actual form array to be built.
Date::buildOptionsForm in core/modules/views/src/Plugin/views/field/Date.php
DateTimeFormatterBase::settingsForm in core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php
Returns a form to configure settings for the formatter.
RegionalForm::buildForm in core/modules/system/src/Form/RegionalForm.php
Form constructor.
SiteConfigureForm::buildForm in core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php
Form constructor.

... See full list

File

core/lib/Drupal/Core/Datetime/TimeZoneFormHelper.php, line 53

Class

TimeZoneFormHelper
Helper class for dealing with timezones.

Namespace

Drupal\Core\Datetime

Code

public static function getOptionsListByRegion(bool $blank = FALSE) : array {
    $zones = static::getOptionsList($blank);
    $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]);
        }
    }
    return $grouped_zones;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.