You are here

public static function RemoteImageItem::generateSampleValue in Remote image 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 LinkItem::generateSampleValue

File

src/Plugin/Field/FieldType/RemoteImageItem.php, line 204
Contains Drupal\remote_image\Plugin\Field\FieldType\RemoteImageField.

Class

RemoteImageItem
Plugin implementation of the 'remote_image' field type.

Namespace

Drupal\remote_image\Plugin\Field\FieldType

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {

  // @todo: respect the remote image settings here.
  // Generate random dimensions.
  $width = mt_rand(100, 1024);
  $height = mt_rand(100, 1024);

  // Use \Drupal\Component\Utility\Random.
  $random = new Random();
  return [
    'uri' => "http://placehold.it/{$width}x{$height}",
    'alt' => $random
      ->sentences(4),
    'title' => $random
      ->sentences(4),
    'width' => $width,
    'height' => $height,
  ];
}