function ListFloatItem::simplifyAllowedValues

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

Overrides ListItemBase::simplifyAllowedValues

File

core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php, line 94

Class

ListFloatItem
Plugin implementation of the 'list_float' field type.

Namespace

Drupal\options\Plugin\Field\FieldType

Code

public static function simplifyAllowedValues(array $structured_values) {
    $values = [];
    foreach ($structured_values as $item) {
        // Nested elements are embedded in the label.
        if (is_array($item['label'])) {
            $item['label'] = static::simplifyAllowedValues($item['label']);
        }
        // Cast the value to a float first so that .5 and 0.5 are the same value
        // and then cast to a string so that values like 0.5 can be used as array
        // keys.
        // @see http://php.net/manual/language.types.array.php
        $values[(string) (double) $item['value']] = $item['label'];
    }
    return $values;
}

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