See the change record: drupal_get_message() and drupal_set_message() replaced by Messenger service.

In our case, this even leads to test fails because we explicitly check $_SESSION['messages'] in our QueryTest. But, while we're at it, we should fix this properly, get rid of the deprecated drupal_set_message() calls and use DI wherever possible for the new messenger service.

One thing I don't quite get is why \Drupal::messenger() doesn't get you the new messenger service but a LegacyMessenger object, which apparently uses the old session mechanism instead of the new flashbag thingie. Therefore, I'm not 100% sure what's the correct replacement for drupal_set_message() calls in procedural code (or other code where DI isn't possible).

Comments

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new63.63 KB
drunken monkey’s picture

StatusFileSize
new1.3 KB

Oops. Lucky that I thought of that in time …
Seems we'll have to wait until we depend on 8.5 before we can do the proper fix/adaption. For now, let's just fix the test.

drunken monkey’s picture

StatusFileSize
new826 bytes
new1.33 KB

OK, makes sense. Then maybe like this?

  • drunken monkey committed 510e3f9 on 8.x-1.x
    Issue #2931730 by drunken monkey: Adapted tests to changes in...
drunken monkey’s picture

Status: Needs review » Postponed

Committed.
Setting back to "Postponed" for the more thorough overhaul in #2 (once we depend on Drupal 8.5).

drunken monkey’s picture

Issue tags: +Drupal 8.5 dependency
drunken monkey’s picture

Status: Postponed » Needs review

The last submitted patch, 2: 2931730-2--use_messenger_service.patch, failed testing. View results

drunken monkey’s picture

StatusFileSize
new63.63 KB

Re-roll of #2.

borisson_’s picture

Status: Needs review » Needs work

I applied this patch, we have 2 leftover instances of drupal_set_message.

src/Form/IndexClearConfirmForm.php
73:      drupal_set_message($this->t('All items were successfully deleted from search index %name.', ['%name' => $index->label()]));

src/Form/IndexRebuildTrackerConfirmForm.php
42:    drupal_set_message($this->t('The tracking information for search index %name will be rebuilt.', ['%name' => $index->label()]));

Those should be changed as well.

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new3.16 KB
new64.76 KB

Good catch, thanks!

chanderbhushan’s picture

@drunken monkey, I have tested your patch, it looks fine.

drunken monkey’s picture

Status: Needs review » Fixed

Thanks a lot, good to hear!
Committed.

  • drunken monkey committed 1c48ee2 on 8.x-1.x
    Issue #2931730 by drunken monkey, borisson_, chanderbhushan: Adapted to...
borisson_’s picture

Status: Needs review » Fixed

For some reason the new status didn't stick.

Status: Fixed » Closed (fixed)

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