You are here

public static function TimeZoneItem::generateSampleValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/TimeZoneItem.php \Drupal\user\TimeZoneItem::generateSampleValue()
  2. 10 core/modules/user/src/TimeZoneItem.php \Drupal\user\TimeZoneItem::generateSampleValue()

Generates placeholder field values.

Useful when populating site with placeholder content during site building or profiling.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

Return value

array An associative array of values.

Overrides StringItem::generateSampleValue

File

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

Class

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

Namespace

Drupal\user

Code

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];
}