You are here

function ga_push_form_validate_get_validate_errors in GA Push 8

Same name and namespace in other branches
  1. 7 modules/form_validate/ga_push_form_validate.module \ga_push_form_validate_get_validate_errors()

Push form errors to GA.

1 string reference to 'ga_push_form_validate_get_validate_errors'
ga_push_form_validate_form_after_build in modules/form_validate/ga_push_form_validate.module
Add the function on the last place to record all errors.

File

modules/form_validate/ga_push_form_validate.module, line 49
Drupal Module: GA Push (form validate).

Code

function ga_push_form_validate_get_validate_errors($form, FormStateInterface $form_state) {
  $errors = $form_state
    ->getErrors();
  if (is_array($errors)) {
    foreach ($errors as $key => $error) {

      // @TODO: filter the error output.
      $push = [
        'eventCategory' => (string) t('Form validate error'),
        'eventAction' => $form['form_id']['#value'] . ' - ' . $key,
        'eventLabel' => (string) $error,
        'eventValue' => 1,
      ];
      ga_push_add_event($push);
    }
  }
}