class TimeZoneItem

Same name and namespace in other branches
  1. 11.x core/modules/user/src/TimeZoneItem.php \Drupal\user\TimeZoneItem

Defines a custom field item class for the 'timezone' user entity field.

Hierarchy

Expanded class hierarchy of TimeZoneItem

1 file declares its use of TimeZoneItem
User.php in core/modules/user/src/Entity/User.php

File

core/modules/user/src/TimeZoneItem.php, line 12

Namespace

Drupal\user
View source
class TimeZoneItem extends StringItem {
  
  /**
   * {@inheritdoc}
   */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $timezones = User::getAllowedTimezones();
    // We need to vary the selected timezones since we're generating a sample.
    $key = rand(0, count($timezones) - 1);
    return $timezones[$key];
  }

}

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