Problem/Motivation
When drupal-check tool is run against the module, it shows the deprecated functions:
Call to deprecated function drupal_set_message():
in drupal:8.5.0 and is removed from drupal:9.0.0.
Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead
This function needs to be removed for Drupal 9 compatibility.
Proposed resolution
The proposed resolution is to replace the deprecated function with \Drupal\Core\Messenger\MessengerInterface::addMessage().
Remaining tasks
I'm preparing the patch at the moment.
Release notes snippet
Replace the deprecated drupal_set_message() function.
Comments
Comment #2
hocuHere's a patch that replaces the deprecated function.
Comment #3
hugronaphor commentedYou can just use
$messenger->addError()instead.Also, string translation.
Comment #4
scott_euser commentedLooks good! Just a couple minor things:
Perhaps you can put the $messenger loading inside the if statement so it is loaded only when needed.
You can actually just user $messenger->addError() here instead of needing the $messenger::TYPE_ERROR
Some extra spaces were added in the code here at the end of the file (nitpick)
Comment #5
hocuThanks @hugronaphor and @scott_euser. I've maked recommended changes and here's the latest patch.
Comment #6
kswamy commentedUPdated patch with code review fixes.
Comment #7
scott_euser commentedLooks good to me! Is `$this->t()` available instead of just `t()`? Not sure. Otherwise RTBC+1 from me.
Comment #8
hocuApparently it's not available:
Error: Using $this when not in object context.Comment #9
nathandentzau@hocu FYI
$thisis not available in a static context, aka a static method on an object. I just tested this locally and looks good. RTBC.Comment #10
nathandentzauComment #11
hocuWonderful! Thanks @nathandentzau and everyone for your great help with this ticket.
Comment #12
hocuComment #13
hocuComment #15
hocuComment #16
hocu