You are here

public function FieldItemList::generateSampleItems in Drupal 10

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

Populates a specified number of field items with valid sample data.

Parameters

int $count: The number of items to create.

Overrides FieldItemListInterface::generateSampleItems

1 method overrides FieldItemList::generateSampleItems()
ModerationStateFieldItemList::generateSampleItems in core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php
Populates a specified number of field items with valid sample data.

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 249

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 = $field_definition
    ->getItemDefinition()
    ->getClass();
  for ($delta = 0; $delta < $count; $delta++) {
    $values[$delta] = $field_type_class::generateSampleValue($field_definition);
  }
  $this
    ->setValue($values);
}