public static function generateSampleValue(FieldDefinitionInterface
$field_definition) { $random =
new Random();
$settings =
$field_definition->
getSettings();
// Prepare destination.
$dirname =
static::
doGetUploadLocation($settings);
\Drupal::
service('file_system'
)->
prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY
);
// Generate a file entity.
$destination =
$dirname . '/' .
$random->
name(10, TRUE
) . '.txt';
$data =
$random->
paragraphs(3
);
/** @var \Drupal\file\FileRepositoryInterface $file_repository */
$file_repository = \Drupal::
service('file.repository'
);
$file =
$file_repository->
writeData($data,
$destination, FileSystemInterface::EXISTS_ERROR
);
$values =
[ 'target_id' =>
$file->
id(),
'display' =>
(int) $settings['display_default'
],
'description' =>
$random->
sentences(10
),
];
return $values;
}