function UriItem::generateSampleValue
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php \Drupal\Core\Field\Plugin\Field\FieldType\UriItem::generateSampleValue()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php \Drupal\Core\Field\Plugin\Field\FieldType\UriItem::generateSampleValue()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php \Drupal\Core\Field\Plugin\Field\FieldType\UriItem::generateSampleValue()
Overrides StringItem::generateSampleValue
2 calls to UriItem::generateSampleValue()
- EntityFile::processStubRow in core/
modules/ file/ src/ Plugin/ migrate/ destination/ EntityFile.php - Populates as much of the stub row as possible.
- UriItemTest::testGenerateSampleValue in core/
tests/ Drupal/ Tests/ Core/ Field/ UriItemTest.php - Tests generating sample values.
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ UriItem.php, line 81
Class
- UriItem
- Defines the 'uri' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random();
$max_length = $field_definition->getSetting('max_length');
$min_length = min(10, $max_length);
// The random value is generated multiple times to create a slight
// preference towards values that are closer to the minimum length of the
// string.
$length = mt_rand($min_length, mt_rand($min_length, mt_rand($min_length, $max_length)));
$values['value'] = $random->word($length);
$suffix_length = $max_length - 7;
foreach ($values as $key => $value) {
$values[$key] = 'http://' . mb_substr($value, 0, $suffix_length);
}
return $values;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.