protected static function extractAllowedValues($string, $has_data) {
    $values = [];

    $list = explode("\n", $string);
    $list = array_map('trim', $list);
    $list = array_filter($list, 'strlen');

    foreach ($list as $position => $text) {
      // Check for an explicit key.
      $matches = [];
      // @TODO Explicit key is necessary !
      if (preg_match('/(.*)\|(.*)\|(.*)/', $text, $matches)) {
        // Trim key and value to avoid unwanted spaces issues.
        $value = trim($matches[1]);
        $label = trim($matches[2]);
        $description = trim($matches[3]);

        $values[$value] = [
          'value' => $value,
          'label' => $label,
          'description' => $description,
        ];
      }
      elseif (preg_match('/(.*)\|(.*)/', $text, $matches)) {
        // Trim key and value to avoid unwanted spaces issues.
        $value = trim($matches[1]);
        $label = trim($matches[2]);
        $values[$value] = [
          'value' => $value,
          'label' => $label,
        ];
      }
    }

    return $values;
  }
protected static function extractAllowedValues($string, $has_data) {
    $values = [];

    $list = explode("\n", $string);
    $list = array_map('trim', $list);
    $list = array_filter($list, 'strlen');

    foreach ($list as $position => $text) {
      // Check for an explicit key.
      $matches = [];
      // @TODO Explicit key is necessary !
      if (preg_match('/(.*)\|(.*)\|(.*)/', $text, $matches)) {
        // Trim key and value to avoid unwanted spaces issues.
        $value = trim($matches[1]);
        $label = trim($matches[2]);
        $description = trim($matches[3]);

        $values[$value] = [
          'value' => $value,
          'label' => $label,
          'description' => $description,
        ];
      }
      elseif (preg_match('/(.*)\|(.*)/', $text, $matches)) {
        // Trim key and value to avoid unwanted spaces issues.
        $value = trim($matches[1]);
        $label = trim($matches[2]);
        $values[$value] = [
          'value' => $value,
          'label' => $label,
        ];
      }
    }

    return $values;
  }
protected static function extractAllowedValues ( $ string , $ has_data ) { $ values = [ ] ; $ list = explode ( "\n" , $ string ) ; $ list = array_map ( 'trim' , $ list ) ; $ list = array_filter ( $ list , 'strlen' ) ; foreach ( $ list as $ position => $ text ) { // Check for an explicit key. $ matches = [ ] ; // @TODO Explicit key is necessary ! if ( preg_match ( '/(.*)\|(.*)\|(.*)/' , $ text , $ matches ) ) { // Trim key and value to avoid unwanted spaces issues. $ value = trim ( $ matches [ 1 ] ) ; $ label = trim ( $ matches [ 2 ] ) ; $ description = trim ( $ matches [ 3 ] ) ; $ values [ $ value ] = [ 'value' => $ value , 'label' => $ label , 'description' => $ description , ] ; } elseif ( preg_match ( '/(.*)\|(.*)/' , $ text , $ matches ) ) { // Trim key and value to avoid unwanted spaces issues. $ value = trim ( $ matches [ 1 ] ) ; $ label = trim ( $ matches [ 2 ] ) ; $ values [ $ value ] = [ 'value' => $ value , 'label' => $ label , ] ; } } return $ values ; }
Extracts the allowed values array from the allowed_values element.

@param string $string
The raw string to extract values from.
@param bool $has_data
The current field already has data inserted or not.

@return array|null
The array of extracted key/value pairs, or NULL if the string is invalid.

@see \Drupal\options\Plugin\Field\FieldType\ListTextItem::allowedValuesString()
Extracts the allowed values array from the allowed_values element .