You are here

function _googleanalytics_extract_create_field_values in Google Analytics 6.4

Same name and namespace in other branches
  1. 7.2 googleanalytics.admin.inc \_googleanalytics_extract_create_field_values()

Extracts the values array from the element.

Parameters

string $string: The raw string to extract values from.

Return value

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

See also

\Drupal\options\Plugin\Field\FieldType\ListTextItem::allowedValuesString()

2 calls to _googleanalytics_extract_create_field_values()
googleanalytics_admin_settings_form_validate in ./googleanalytics.admin.inc
googleanalytics_validate_create_field_values in ./googleanalytics.admin.inc
#element_validate callback for create only fields.

File

./googleanalytics.admin.inc, line 721
Administrative page callbacks for the googleanalytics module.

Code

function _googleanalytics_extract_create_field_values($string) {
  $values = array();
  $list = explode("\n", $string);
  $list = array_map('trim', $list);
  $list = array_filter($list, 'strlen');
  foreach ($list as $text) {

    // Check for an explicit key.
    $matches = array();
    if (preg_match('/(.*)\\|(.*)/', $text, $matches)) {

      // Trim key and value to avoid unwanted spaces issues.
      $name = trim($matches[1]);
      $value = trim($matches[2]);
    }
    else {
      return;
    }
    $values[$name] = $value;
  }
  return _googleanalytics_convert_form_value_data_types($values);
}