You are here

protected static function GoogleAnalyticsAdminSettingsForm::extractCreateFieldValues in Google Analytics 8.2

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()

1 call to GoogleAnalyticsAdminSettingsForm::extractCreateFieldValues()
GoogleAnalyticsAdminSettingsForm::validateCreateFieldValues in src/Form/GoogleAnalyticsAdminSettingsForm.php
The #element_validate callback for create only fields.

File

src/Form/GoogleAnalyticsAdminSettingsForm.php, line 916

Class

GoogleAnalyticsAdminSettingsForm
Configure Google_Analytics settings for this site.

Namespace

Drupal\google_analytics\Form

Code

protected static function extractCreateFieldValues($string) {
  $values = [];
  $list = explode("\n", $string);
  $list = array_map('trim', $list);
  $list = array_filter($list, 'strlen');
  foreach ($list as $text) {

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

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