Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / user / src / TimeZoneItem.php
diff --git a/web/core/modules/user/src/TimeZoneItem.php b/web/core/modules/user/src/TimeZoneItem.php
new file mode 100644 (file)
index 0000000..f109691
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\user;
+
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
+use Drupal\user\Entity\User;
+
+/**
+ * Defines a custom field item class for the 'timezone' user entity field.
+ */
+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];
+  }
+
+}