function TimeZoneFormHelper::getOptionsList

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

Generate an array of time zones names.

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 array or nested array containing time zones, keyed by the system name. The keys are valid time zone identifiers provided by \DateTimeZone::listIdentifiers()

3 calls to TimeZoneFormHelper::getOptionsList()
TimeZoneFormHelper::getOptionsListByRegion in core/lib/Drupal/Core/Datetime/TimeZoneFormHelper.php
Generate an array of time zones names grouped by region.
TimeZoneFormHelperTest::testGetList in core/tests/Drupal/Tests/Core/Datetime/TimeZoneFormHelperTest.php
@covers ::getOptionsList @covers ::getOptionsListByRegion
UserUpdate7002::__construct in core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php

File

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

Class

TimeZoneFormHelper
Helper class for dealing with timezones.

Namespace

Drupal\Core\Datetime

Code

public static function getOptionsList(bool $blank = FALSE) : array {
    $zone_list = \DateTimeZone::listIdentifiers();
    $zones = $blank ? [
        '' => new TranslatableMarkup('- None selected -'),
    ] : [];
    foreach ($zone_list as $zone) {
        $zones[$zone] = new TranslatableMarkup(str_replace('_', ' ', $zone));
    }
    // Sort the translated time zones alphabetically.
    asort($zones);
    return $zones;
}

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