You are here

public static function EntityBlockItem::generateSampleValue in Entityblock 8

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 FieldItemBase::generateSampleValue

File

src/Plugin/Field/FieldType/EntityBlockItem.php, line 111
Contains \Drupal\entityblock\Plugin\Field\FieldType\EntityBlockItem.

Class

EntityBlockItem
Plugin implementation of the 'EntityBlock' field type.

Namespace

Drupal\entityblock\Plugin\Field\FieldType

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
  $view_modes = \Drupal::entityTypeManager()
    ->getViewModes($field_definition
    ->getTargetEntityTypeId());
  $random = new Random();
  $values = array(
    'enabled' => rand(0, 1),
    'title' => $random
      ->sentences(1),
    'view_mode' => array_rand($view_modes),
  );
  return $values;
}