You are here

function matomo_token_element_validate in Matomo Analytics 7.2

Validate a form element that should have tokens in it.

For example:

$form['my_node_text_element'] = array(
  '#type' => 'textfield',
  '#title' => t('Some text to token-ize that has a node context.'),
  '#default_value' => 'The title of this node is [node:title].',
  '#element_validate' => array(
    'matomo_token_element_validate',
  ),
);
1 string reference to 'matomo_token_element_validate'
matomo_admin_settings_form in ./matomo.admin.inc
Implements hook_admin_settings() for configuring the module.

File

./matomo.admin.inc, line 550
Administrative page callbacks for the matomo module.

Code

function matomo_token_element_validate(&$element, &$form_state) {
  $value = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
  if (!drupal_strlen($value)) {

    // Empty value needs no further validation since the element should depend
    // on using the '#required' FAPI property.
    return $element;
  }
  $tokens = token_scan($value);
  $invalid_tokens = _matomo_get_forbidden_tokens($tokens);
  if ($invalid_tokens) {
    form_error($element, t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array(
      '%element-title' => $element['#title'],
      '@invalid-tokens' => implode(', ', $invalid_tokens),
    )));
  }
  return $element;
}