summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-11-02 16:36:30 (GMT)
committerAlex Pott2015-11-02 16:36:30 (GMT)
commitcbef10d7144f6db4136d35a8c05e51eeb2a5b5ea (patch)
treeb9016eb23a3ea5e0e1aeefaeb40394a824cd37c6
parent573fab03c7867bcf6800d28d96a9fa611f367ae8 (diff)
Issue #2536374 by DuaelFr: Generate placeholder content for ListItemBase Field types
-rw-r--r--core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php4
-rw-r--r--core/modules/options/src/Tests/OptionsFieldTest.php1
2 files changed, 4 insertions, 1 deletions
diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
index bbca170..6395028 100644
--- a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
+++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
@@ -71,7 +71,9 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
- // @todo Implement this once https://www.drupal.org/node/2238085 lands.
+ $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition());
+ $values['value'] = array_rand($allowed_options);
+ return $values;
}
/**
diff --git a/core/modules/options/src/Tests/OptionsFieldTest.php b/core/modules/options/src/Tests/OptionsFieldTest.php
index 0380ec0..a7d3ffe 100644
--- a/core/modules/options/src/Tests/OptionsFieldTest.php
+++ b/core/modules/options/src/Tests/OptionsFieldTest.php
@@ -80,6 +80,7 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
+ 'required' => TRUE,
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->fieldName, array(