Skip to content
Snippets Groups Projects
Commit ea543f14 authored by Angie Byron's avatar Angie Byron
Browse files

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

parent 41e882f4
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\Core\Field\Plugin\Field\FieldType; 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\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataDefinition;
...@@ -77,4 +79,16 @@ public function isEmpty() { ...@@ -77,4 +79,16 @@ public function isEmpty() {
return parent::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() { ...@@ -68,6 +68,11 @@ public function testUriField() {
'type' => 'uri', 'type' => 'uri',
]) ])
->save(); ->save();
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity->$field_name->generateSampleItems();
$this->entityValidateAndSave($entity);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment