drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.


We have to replace all usage of drupal_set_message() with an injectible service as described in #2278383: Create an injectible service for drupal_set_message()

Change record: https://www.drupal.org/node/2774931

The deprecation was added in Drupal 8.5 but suppressed until 8.6 hence we only started getting Travis test failures at 8.6.

Comments

legovaer created an issue. See original summary.

legovaer’s picture

Postponed as the core team is still working on the service.

idebr’s picture

Snehal Brahmbhatt’s picture

Status: Active » Needs review
StatusFileSize
new6.79 KB

@legovaer, Please find my patch that Changes the drupal_set_message to $this->messenger->addMessage as per Drupal standard. Hope this helps you.

Thanks!.

Status: Needs review » Needs work

The last submitted patch, 4: scheduler-2705499-4.patch, failed testing. View results

legovaer’s picture

Thank you for your patch. However you are calling the messenger using $this->messenger however this was never set. It would be better to get the service via \Drupal::service() so that other people won't get confused.

thalles’s picture

Assigned: Unassigned » thalles
thalles’s picture

Assigned: thalles » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.39 KB

Follow the patch!

idebr’s picture

Status: Needs review » Reviewed & tested by the community

The patch applies cleanly and replaces all occurrences of drupal_set_message() with the Messenger service.

  • jonathan1055 committed 7758541 on 8.x-1.x authored by thalles
    Issue #2705499 by thalles, snehal.addweb, legovaer, idebr: Replace...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Thanks snehal.addweb, legovaer, thales and idebr.

thalles’s picture

Thanks all!

jonathan1055’s picture

Just to record the effect this had, here are screen shots from my test builds on https://travis-ci.org/jonathan1055/scheduler

Before:
before

After:
after

The remaining failures were in the Devel Generate code itself, so had to be suppressed using @group legacy which I did in #3033108-6: Miscellaneous changes before Scheduler 8.x-1.1

jonathan1055’s picture

jonathan1055’s picture

Issue summary: View changes

The replacement messenger service does not exist in core 8.4, it was added in 8.5 so Scheduler now needs to explicitly state that it is only compatible with Drupal Core 8.5 and higher. Hence adding - drupal:system (>= 8.5) to scheduler.info.yml

  • jonathan1055 committed e246f3a on 8.x-1.x
    Issue #2705499 by jonathan1055: Specify that Scheduler 8.x-1.1 requires...

Status: Fixed » Closed (fixed)

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