function ListItemBase::structureAllowedValues

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

Creates a structured array of allowed values from a key-value array.

Parameters

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

Return value

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

See also

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

1 call to ListItemBase::structureAllowedValues()
ListItemBase::storageSettingsToConfigData in core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
Returns a settings array that can be stored as a configuration value.

File

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

Class

ListItemBase
Plugin base class inherited by the options field types.

Namespace

Drupal\options\Plugin\Field\FieldType

Code

protected static function structureAllowedValues(array $values) {
    $structured_values = [];
    foreach ($values as $value => $label) {
        if (is_array($label)) {
            $label = static::structureAllowedValues($label);
        }
        $structured_values[] = [
            'value' => static::castAllowedValue($value),
            'label' => $label,
        ];
    }
    return $structured_values;
}

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