function TextItemBase::generateSampleValue
Same name in other branches
- 9 core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php \Drupal\text\Plugin\Field\FieldType\TextItemBase::generateSampleValue()
- 10 core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php \Drupal\text\Plugin\Field\FieldType\TextItemBase::generateSampleValue()
- 11.x core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php \Drupal\text\Plugin\Field\FieldType\TextItemBase::generateSampleValue()
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.