Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Add field storage with grouped allowed values fails.
exception 'InvalidArgumentException' with message 'The configuration property settings.allowed_values.0.label.0 doesn't exist.' in core/lib/Drupal/Core/Config/Schema/ArrayElement.php:79
Flat allowed values works.
'allowed_values' => array(
'Value 0' => 'Zero',
1 => 'One',
2 => 'Two',
3 => 'Three',
)
Steps to reproduce
Creating a list_string field with grouping in the allowed values.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_test_optgroup',
'entity_type' => 'node',
'type' => 'list_string',
'cardinality' => 1,
'settings' => [
'allowed_values' => [
'Group 1' => [
0 => 'Zero',
],
1 => 'One',
'Group 2' => [
2 => 'Some markup',
],
'More markup' => [
3 => 'Three',
],
],
'allowed_values_function' => '',
],
]
);
$field_storage->save();
$field = FieldConfig::create([
'field_name' => 'field_test_optgroup',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Testing optgroup',
]);
$field->save();
Comments
Comment #2
amaria CreditAttribution: amaria commentedComment #3
amaria CreditAttribution: amaria commentedComment #10
quietone CreditAttribution: quietone at PreviousNext commentedThis was discussed at a bugsmash group triage meeting. larowlan stated that this is a feature request. I am tagging and changing the category.