function ListItemBase::simplifyAllowedValues

Same name in other branches
  1. 9 core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php \Drupal\options\Plugin\Field\FieldType\ListItemBase::simplifyAllowedValues()
  2. 8.9.x core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php \Drupal\options\Plugin\Field\FieldType\ListItemBase::simplifyAllowedValues()
  3. 10 core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php \Drupal\options\Plugin\Field\FieldType\ListItemBase::simplifyAllowedValues()

Simplifies allowed values to a key-value array from the structured array.

Parameters

array $structured_values: Array of items with a 'value' and 'label' key each for the allowed values.

Return value

array Allowed values were the array key is the 'value' value, the value is the 'label' value.

See also

\Drupal\options\Plugin\Field\FieldType\ListItemBase::structureAllowedValues()

1 call to ListItemBase::simplifyAllowedValues()
ListItemBase::storageSettingsFromConfigData in core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
Returns a settings array in the field type's canonical representation.
1 method overrides ListItemBase::simplifyAllowedValues()
ListFloatItem::simplifyAllowedValues in core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php
Simplifies allowed values to a key-value array from the structured array.

File

core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php, line 507

Class

ListItemBase
Plugin base class inherited by the options field types.

Namespace

Drupal\options\Plugin\Field\FieldType

Code

protected static function simplifyAllowedValues(array $structured_values) {
    $values = [];
    foreach ($structured_values as $item) {
        if (is_array($item['label'])) {
            // Nested elements are embedded in the label.
            $item['label'] = static::simplifyAllowedValues($item['label']);
        }
        $values[$item['value']] = $item['label'];
    }
    return $values;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.