$description .= '<br/>' .
$this->
t('The label is optional: if a line contains a single number, it will be used as key and label.'
);
$description .= '<br/>' .
$this->
t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'
);
$description .= '</p>';
$description .= '<p>' .
$this->
t('Allowed HTML tags in labels: @tags',
['@tags' => FieldFilteredMarkup::
displayAllowedTags()]) . '</p>';
return $description;
} /**
* {@inheritdoc}
*/
protected static function extractAllowedValues($string,
$has_data) { $values = parent::
extractAllowedValues($string,
$has_data);
if ($values) { $keys =
array_keys($values);
$labels =
array_values($values);
$keys =
array_map(function D
$key) { // Float keys are represented as strings and need to be disambiguated
// ('.5' is '0.5').
return is_numeric($key) ?
(string) (float) $key :
$key;
},
$keys);
return array_combine($keys,
$labels);
}