You are here

protected static function ListItemBase::structureAllowedValues in Drupal 9

Same name and namespace in other branches
  1. 8 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 304

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;
}