Loading core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php +4 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,10 @@ public function getSettableOptions(AccountInterface $account = NULL) { */ public static function generateSampleValue(FieldDefinitionInterface $field_definition) { $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition()); if (empty($allowed_options)) { $values['value'] = NULL; return $values; } $values['value'] = array_rand($allowed_options); return $values; } Loading core/modules/options/tests/src/Kernel/OptionsFieldTest.php +10 −0 Original line number Diff line number Diff line Loading @@ -98,4 +98,14 @@ public function testUpdateAllowedValues() { $this->entityValidateAndSave($entity); } /** * Tests that ::generateSampleItems does not fail with empty allowed values. */ public function testGenerateSampleItemsWithNoAllowedValues() { $this->fieldStorage->setSetting('allowed_values', [])->save(); $entity = EntityTest::create(); $value = $entity->{$this->fieldName}->generateSampleItems(); $this->assertNull($value); } } Loading
core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php +4 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,10 @@ public function getSettableOptions(AccountInterface $account = NULL) { */ public static function generateSampleValue(FieldDefinitionInterface $field_definition) { $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition()); if (empty($allowed_options)) { $values['value'] = NULL; return $values; } $values['value'] = array_rand($allowed_options); return $values; } Loading
core/modules/options/tests/src/Kernel/OptionsFieldTest.php +10 −0 Original line number Diff line number Diff line Loading @@ -98,4 +98,14 @@ public function testUpdateAllowedValues() { $this->entityValidateAndSave($entity); } /** * Tests that ::generateSampleItems does not fail with empty allowed values. */ public function testGenerateSampleItemsWithNoAllowedValues() { $this->fieldStorage->setSetting('allowed_values', [])->save(); $entity = EntityTest::create(); $value = $entity->{$this->fieldName}->generateSampleItems(); $this->assertNull($value); } }