Commit ea543f14 authored by webchick's avatar webchick

Issue #2605150 by mikeryan: UrlItem::generateSampleValue() does not generate a valid uri

parent 41e882f4
......@@ -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 @@ public function isEmpty() {
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 @@ public function testUriField() {
'type' => 'uri',
])
->save();
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity->$field_name->generateSampleItems();
$this->entityValidateAndSave($entity);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment