You are here

public function FieldItemList::generateSampleItems in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::generateSampleItems()

Overrides FieldItemListInterface::generateSampleItems

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 265
Contains \Drupal\Core\Field\FieldItemList.

Class

FieldItemList
Represents an entity field; that is, a list of field item objects.

Namespace

Drupal\Core\Field

Code

public function generateSampleItems($count = 1) {
  $field_definition = $this
    ->getFieldDefinition();
  $field_type_class = \Drupal::service('plugin.manager.field.field_type')
    ->getPluginClass($field_definition
    ->getType());
  for ($delta = 0; $delta < $count; $delta++) {
    $values[$delta] = $field_type_class::generateSampleValue($field_definition);
  }
  $this
    ->setValue($values);
}