public static function VideoItem::generateSampleValue in Video 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldType/VideoItem.php \Drupal\video\Plugin\Field\FieldType\VideoItem::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 FileItem::generateSampleValue
File
- src/
Plugin/ Field/ FieldType/ VideoItem.php, line 152
Class
- VideoItem
- Plugin implementation of the 'video' field type.
Namespace
Drupal\video\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random();
$settings = $field_definition
->getSettings();
// Prepare destination.
$dirname = static::doGetUploadLocation($settings);
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
// Generate a file entity.
$destination = $dirname . '/' . $random
->name(10, TRUE) . '.mp4';
$data = $random
->paragraphs(3);
$file = file_save_data($data, $destination, FILE_EXISTS_ERROR);
$values = [
'target_id' => $file
->id(),
];
return $values;
}