system_time_zones() is deprecated in drupal:10.1.0

Created on 13 July 2023, over 1 year ago
Updated 6 April 2024, 8 months ago

Problem/Motivation

system_time_zones() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. This function is no longer used in Drupal core. Use \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(), \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsListByRegion() or \DateTimeZone::listIdentifiers() instead. See https://www.drupal.org/node/3023528

There appear to be two places that need to be updated:

in /Plugin/FieldType/SmartDateItem.php, line 79:
->addConstraint('AllowedValues', array_keys(system_time_zones(TRUE, FALSE)));

Should be:
->addConstraint('AllowedValues', array_keys(TimeZoneFormHelper::getOptionsList(TRUE)));
(Needs use statement for \Drupal\Core\Datetime\TimeZoneFormHelper)

in /Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php, line 165:
return system_time_zones(FALSE, $grouped);

Should be:
return $grouped ? TimeZoneFormHelper::getOptionsListByRegion(FALSE) : TimeZoneFormHelper::getOptionsList(FALSE);
(Needs use statement for \Drupal\Core\Datetime\TimeZoneFormHelper)

Additionally, the above use of TimeZoneFormHelper::getOptionsList will mean requiring Drupal 10.1 or newer.

📌 Task
Status

Fixed

Version

4.1

Component

Code

Created by

🇩🇪Germany sleitner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024