You are here

public static function UriItem::generateSampleValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php \Drupal\Core\Field\Plugin\Field\FieldType\UriItem::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

1 call to UriItem::generateSampleValue()
EntityFile::processStubRow in core/modules/file/src/Plugin/migrate/destination/EntityFile.php
Populates as much of the stub row as possible.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php, line 79

Class

UriItem
Defines the 'uri' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
  $values = parent::generateSampleValue($field_definition);
  $suffix_length = $field_definition
    ->getSetting('max_length') - 7;
  foreach ($values as $key => $value) {
    $values[$key] = 'http://' . mb_substr($value, 0, $suffix_length);
  }
  return $values;
}