Error: Call to a member function __toString() on string

Created on 13 January 2023, almost 2 years ago
Updated 18 January 2023, almost 2 years ago

Problem/Motivation

In RouteInModalAjaxHelper::ajaxCallback(), the following

...
$messages = \Drupal::messenger()->all();
$config = \Drupal::config('route_in_modal.settings');

if (!isset($messages['error'])) {
...
if ($confirmationMessagesModal && count($messages) > 0) {
        \Drupal::messenger()->deleteAll();

        $display = strip_tags($messages['status'][0]->__toString());

throws

Error: Call to a member function __toString() on string

if a message is a string and not a MarkupInterface.

In addition, only the first message is shown while all are deleted.
Also, there is no guarantee that the first message will be the one that is desired to be shown.
As far as I'm aware, there is no way to determine from a message where came from and if it is directly related to the action just performed, whatever it may be..

Proposed resolution

I think the safest approach for now is to show all messages, which also might include notices.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇪Belgium andreasderijcke Antwerpen / Gent

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024