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();

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

amaria created an issue. See original summary.

amaria’s picture

Title: Setting allowed fields with grouping causes a "InvalidArgumentException" » Setting lallowed values with grouping on list fields causes a "InvalidArgumentException"
amaria’s picture

Title: Setting lallowed values with grouping on list fields causes a "InvalidArgumentException" » Setting allowed values with grouping on list fields causes a "InvalidArgumentException" error

Version: 8.0.1 » 8.0.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.0.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.5.x-dev » 10.1.x-dev
Category: Bug report » Feature request
Issue summary: View changes
Issue tags: -options, -allowed values, -optgroup, -select list +Bug Smash Initiative

This was discussed at a bugsmash group triage meeting. larowlan stated that this is a feature request. I am tagging and changing the category.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.