Problem/Motivation

The GoogleAnalyticsStatusMessagesTest fails currently because the errors for required username/passsword fields is currently not returned as an error anymore. Instead they were combined into one error which we test for now. A new issue to add back the username/passsword field is required messages is here.

Proposed resolution

Replace current assert with one that matches what is present (though with less information), add a todo which indicates that there is still work to do, provide patch, commit it.

Remaining tasks

Review patch, commit.

User interface changes

None

API changes

None

Comments

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB

Here is a patch. I'm not sure if it really is an equivalent. Seems like it used to show more detailed information.

hass’s picture

Status: Needs review » Needs work

This is an incorrect change.

We do not like to look for the messages visible to a user. We need to verify if the *tracking code* is shown.

LKS90’s picture

StatusFileSize
new1.12 KB

Quick search in the source for ga( and I found it.

LKS90’s picture

Status: Needs work » Needs review
hass’s picture

What bullshit patch has changed the text to these useless error messages??? This errors will not explain a user what gone wrong and how I'm able to solve the form error.

hass’s picture

Status: Needs review » Needs work

I've tested this on simplytest.me, but it is not what we want.

We need the message text in google analytics - not the error counter and field list that has errors.

It looks like this text is now shown below the field that contains the error.

LKS90’s picture

I'm more confused than before now. Besides the ga('send', ...) with the Error messages, there is nothing on the page related to google analytics. Do you expect some (hidden?) field under the "Username/password field is required"?

Edit: Looks like #2 confused me, an assertText for the 'Username/Password field is required.' like in the first patch plus the line from the second patch seems like all the information we would want at that point, maybe also extend the assertRaw to also include the tracking code, but otherwise I don't get what the test should be testing.

hass’s picture

Sorry for confusion.

We need the "Username/Password field is required." (or how it is spelled today) error message that is now shown below the username form field. This string need to be added inside the ga event tracking code.

You may compare to D7 if it is now confusing... It has been broken by core in last 1-2 weeks.

LKS90’s picture

The issue that broke the test: https://www.drupal.org/node/1493324

The form-error-messages aren't returned by drupal_get_messages though. I don't know how I should get the specific error messages to send, they are attached to the elements on form validation using the form_state.

LKS90’s picture

Alright, patch 3 fixes the test fail.

If you want to track the Username/Password is required information with google analytics, create a new issue and try and implement it. As I said, drupal_get_messages() doesn't treat this as a (form-error/error/message) error so you can't really know exactly what's wrong with the Username and password when sending the error message to google analytics.

I'd just like to get the test fixed and save adding new functionality for a separate issue.

LKS90’s picture

Status: Needs work » Needs review
hass’s picture

Status: Needs review » Needs work

We are not adding new functionality. This is an old feature and if we do not get the error message the old feature is broken. We need to repair this and I do not like to remove the feature. Your change fixes the test, but the feature is still broken.

LKS90’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.24 KB

True, but committing this and moving on to the next issue that focuses on the field errors is probably easier and we can actually get something done instead of discussing things :P.

Here is an issue that properly describes the current problem. I'll edit this issue to reflect that less information is provided at the moment and that the test is now passing.

LKS90’s picture

StatusFileSize
new1.2 KB

Here is a second version without the line removal, just in case... :D

hass’s picture

Status: Needs review » Needs work

This suxxx

use \Drupal\Component\Utility\SafeMarkup;

...
    // Add messages tracking.
    $message_events = '';
    if ($message_types = $config->get('track.messages')) {
      $message_types = array_values(array_filter($message_types));
      $status_heading = [
        'status' => t('Status message'),
        'warning' => t('Warning message'),
        'error' => t('Error message'),
      ];

      foreach (google_analytics_get_messages(NULL, FALSE) as $type => $messages) {
      //foreach (drupal_get_messages(NULL, FALSE) as $type => $messages) {
        // Track only the selected message types.
        if (in_array($type, $message_types)) {
          foreach ($messages as $message) {
            // @todo: Track as exceptions?
            $message_events .= 'ga("send", "event", ' . Json::encode(t('Messages')) . ', ' . Json::encode($status_heading[$type]) . ', ' . Json::encode(strip_tags($message)) . ');';
          }
        }
      }
    }
...

function google_analytics_preprocess_fieldset(&$variables) {
  if ($variables['errors'] !== NULL) {
    google_analytics_set_message($variables['errors'], $type = 'error');
  }
}
function google_analytics_preprocess_form_element(&$variables) {
  if ($variables['errors'] !== NULL) {
    google_analytics_set_message($variables['errors'], $type = 'error');
  }
}
function google_analytics_preprocess_datetime_wrapper(&$variables) {
  if ($variables['errors'] !== NULL) {
    google_analytics_set_message($variables['errors'], $type = 'error');
  }
}

function google_analytics_set_message($message = NULL, $type = 'status', $repeat = FALSE) {
  if (isset($message)) {
    if (!isset($_SESSION ['form_messages'][$type])) {
      $_SESSION ['form_messages'][$type] = array();
    }

    $new = array(
      'safe' => SafeMarkup::isSafe($message),
      'form_messages' => $message,
    );
    if ($repeat || !in_array($new, $_SESSION ['form_messages'][$type])) {
      $_SESSION ['form_messages'][$type][] = $new;
    }

    // Mark this page as being uncacheable.
    \Drupal::service('page_cache_kill_switch')->trigger();
  }

  // Messages not set when DB connection fails.
  return isset($_SESSION ['form_messages']) ? $_SESSION ['form_messages'] : NULL;
}

function google_analytics_get_messages($type = NULL, $clear_queue = TRUE) {
  if ($messages = google_analytics_set_message()) {
    foreach ($messages as $message_type => $message_typed_messages) {
      foreach ($message_typed_messages as $key => $message) {
        // Because the messages are stored in the session, the safe status of
        // the messages also needs to be stored in the session. We retrieve the
        // safe status here and determine whether to mark the string as safe or
        // let autoescape do its thing. See drupal_set_message().
        if ($message ['safe']) {
          $message ['form_messages'] = SafeMarkup::set($message ['form_messages']);
        }
        $messages [$message_type][$key] = $message ['form_messages'];
      }
    }
    if ($type) {
      if ($clear_queue) {
        unset($_SESSION ['form_messages'][$type]);
      }
      if (isset($messages [$type])) {
        return array($type => $messages [$type]);
      }
    }
    else {
      if ($clear_queue) {
        unset($_SESSION ['form_messages']);
      }
      return $messages;
    }
  }
  return array();
}
LKS90’s picture

Title: Update status message test » Fix missing field/form element/datetime errors on form submission
Status: Needs work » Needs review
StatusFileSize
new4.46 KB

Here is a patch with the code above added (and some documentation for it), feedback welcome (german is also possible :P). The test passes and the other error message is gone. Also changing the issue title to match what this patch does.

hass’s picture

Merged the preprecess functions and merged the drupal_get_messages() with the form messages. Fully untested.

It would be good if core is able to provide the form errors with a function.

hass’s picture

StatusFileSize
new4.11 KB

Missed to change one function name.

Status: Needs review » Needs work

The last submitted patch, 18: Issue-2506827-by-hass-Fix-missing-field-form-element.patch, failed testing.

Status: Needs work » Needs review
hass’s picture

BUGs:

  • Form errors seems never deleted.
  • Drupal messages are not merged.
  • We need a solution to remove the useless Drupal error messages that tells us there are X errors in the form.
hass’s picture

StatusFileSize
new4.11 KB

This fixes the not cleared messages issue.

It looks like the drupal_get_messages(NULL, FALSE) is now broken in hook_page_attachments() and does not return anything.

hass’s picture

Status: Needs review » Postponed

The inline patch #2578561: Move "Inline Form Errors" functionality to optional module and restore D7-style form errors by default has been roled back.

We are back to D7 behaviour and the code works again. The feature is now moved to contrib and may come in again in 8.1 or later. Therefore postponed on Drupal 8.1 or later

tim.plunkett’s picture

It wasn't moved to contrib, it is still in core as an optional, "experimental" module. You're right that it won't be back until 8.1 or later though.

mgifford’s picture

So if this "experimental" module is enabled, how will Google Analytics or other contrib modules function? Should modules be coded to work with both? I don't know how much will be different for contrib.

Note, I haven't really had time to look at what was done in Core in the last 5 days.

hass’s picture

The feature may need to be removed completly. With html5 form validation the browser manages the validation and drupal do not get notified. As browsers do not run a callback we are totally blind to what type of form errors happend. That is really bad, but I'm not aware of any reliable workaround :-(

mgifford’s picture

Ok, so now that this module has an RC1, does this error still show up when the experimental inline errors module is enabled?

I'm not sure where to look for it. Steps to reproduce it would be terrific.

hass’s picture

Status: Postponed » Active

The sh** got into core now. Unpostponing, but no idea how we may ever fix it if the browser only does form validation and does not interact with the website.

japerry’s picture

Status: Active » Closed (outdated)

With the sunset of legacy google analytics, the 8.x-2.x module is now unsupported. If this is still an issue with the 4.x version, please file a new issue in the queue.