You are here

function _google_tag_validate_container_id in GoogleTagManager 7

Same name and namespace in other branches
  1. 7.2 includes/variable.inc \_google_tag_validate_container_id()

Element validation handler for google_tag_container_id.

@todo This may suffice for all the elements as only the container_id has an error message. Error messages could be done for other elements by calling form_set_error('element[name]', $message).

1 string reference to '_google_tag_validate_container_id'
_google_tag_variable_info_general in includes/variable.inc
Implements hook_variable_info().

File

includes/variable.inc, line 363
Contains the variable definitions.

Code

function _google_tag_validate_container_id($variable, $options, $element, $form, &$form_state) {

  // Use this routine as the variable realm form has nested values.
  $value = drupal_array_get_nested_value($form_state['values'], $element['#parents']);

  // Trim the text value.
  $value = trim($value);

  // Replace all types of dashes (n-dash, m-dash, minus) with a normal dash.
  $value = str_replace(array(
    '–',
    '—',
    '−',
  ), '-', $value);

  // Replace the text value.
  drupal_array_set_nested_value($form_state['values'], $element['#parents'], $value);
  if (!preg_match('/^GTM-\\w{4,}$/', $value)) {

    // @todo Is there a more specific regular expression that applies?
    // @todo Is there a way to "test the connection" to determine a valid ID for
    // a container? It may be valid but not the correct one for the website.
    return t('A valid container ID is case sensitive and formatted like GTM-xxxxxx.');
  }
}