Issue #2605150 by mikeryan: UrlItem::generateSampleValue() does not generate a valid uri
parent
41e882f41f
commit
ea543f14af
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\Core\Field\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
|
||||
|
@ -77,4 +79,16 @@ class UriItem extends StringItem {
|
|||
return parent::isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
|
||||
$values = parent::generateSampleValue($field_definition);
|
||||
$suffix_length = $field_definition->getSetting('max_length') - 7;
|
||||
foreach ($values as $key => $value) {
|
||||
$values[$key] = 'http://' . Unicode::substr($value, 0, $suffix_length);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,6 +68,11 @@ class UriItemTest extends FieldUnitTestBase {
|
|||
'type' => 'uri',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity->$field_name->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue