public static function TextItemBase::generateSampleValue in Drupal 8
Same name and namespace in other branches
- 9 core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php \Drupal\text\Plugin\Field\FieldType\TextItemBase::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 FieldItemBase::generateSampleValue
File
- core/
modules/ text/ src/ Plugin/ Field/ FieldType/ TextItemBase.php, line 73
Class
- TextItemBase
- Base class for 'text' configurable field types.
Namespace
Drupal\text\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random();
$settings = $field_definition
->getSettings();
if (empty($settings['max_length'])) {
// Textarea handling
$value = $random
->paragraphs();
}
else {
// Textfield handling.
$value = substr($random
->sentences(mt_rand(1, $settings['max_length'] / 3), FALSE), 0, $settings['max_length']);
}
$values = [
'value' => $value,
'summary' => $value,
'format' => filter_fallback_format(),
];
return $values;
}