Just tested Google Analytics migration from D7 to D8 and after the migration completed I got this message. I need to say that this is not my fault in GA. I have only seen this after the Drupal migration completed and no where else.

Upgrade process not completed
Review the detailed upgrade log
Warning: strip_tags() expects parameter 1 to be string, object given in google_analytics_page_attachments() (line 150 of modules\google_analytics\google_analytics.module).

The error comes from this code Json::encode(strip_tags($message)):

      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)) . ');';
          }
        }
      }

A message need to be TEXT only and cannot be a OBJECT. I guess the migration UI or Core has a bug.

Comments

hass created an issue. See original summary.

hass’s picture

Title: drupal_get_messages returns objects as messages » drupal_get_messages incorreclty returns objects as messages
jibran’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

It is supposed to return string or MarkupInterface which has __toString did you try typecasting the it to string?

hass’s picture

No idea how I‘m able to reproduce this situation. I expect string only and do not typecast something that should only be a string.

Based on https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/functi... I think this can only a sring. No word about MarkupInterface.

hass’s picture

Found it. This bad behaviour is new in D8. https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/functi.... An unseen bug for more than 3.5 years.

hass’s picture

Title: drupal_get_messages incorreclty returns objects as messages » drupal_get_messages may returns objects as messages in D8
Project: Drupal core » Google Analytics
Version: 8.5.5 » 8.x-2.x-dev
Component: base system » Code
Category: Support request » Bug report
Status: Postponed (maintainer needs more info) » Active
hass’s picture

Title: drupal_get_messages may returns objects as messages in D8 » drupal_get_messages may returns MarkupInterface objects as messages in D8

  • hass committed c76c82f on 8.x-2.x
    Issue #2985502: drupal_get_messages may returns MarkupInterface objects...

  • hass committed 90823c6 on 8.x-3.x
    Issue #2985502: drupal_get_messages may returns MarkupInterface objects...
hass’s picture

Issue tags: +Needs tests
hass’s picture

Status: Active » Needs work
hass’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.