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

hocu created an issue. See original summary.

hocu’s picture

Status: Active » Needs review
StatusFileSize
new882 bytes

Here's a patch that replaces the deprecated function.

hugronaphor’s picture

You can just use $messenger->addError() instead.
Also, string translation.

scott_euser’s picture

Assigned: hocu » Unassigned
Status: Needs review » Needs work

Looks good! Just a couple minor things:

  1. +++ b/src/Element/AddressCraftyClicks.php
    @@ -78,8 +78,12 @@ class AddressCraftyClicks extends WebformAddress {
         if (!isset($access_token)) {
    

    Perhaps you can put the $messenger loading inside the if statement so it is loaded only when needed.

  2. +++ b/src/Element/AddressCraftyClicks.php
    @@ -78,8 +78,12 @@ class AddressCraftyClicks extends WebformAddress {
    +      $messenger->addMessage(
    

    You can actually just user $messenger->addError() here instead of needing the $messenger::TYPE_ERROR

  3. +++ b/src/Element/AddressCraftyClicks.php
    @@ -92,5 +96,5 @@ class AddressCraftyClicks extends WebformAddress {
    +  ¶
    

    Some extra spaces were added in the code here at the end of the file (nitpick)

hocu’s picture

Status: Needs work » Needs review
StatusFileSize
new950 bytes

Thanks @hugronaphor and @scott_euser. I've maked recommended changes and here's the latest patch.

kswamy’s picture

UPdated patch with code review fixes.

scott_euser’s picture

Looks good to me! Is `$this->t()` available instead of just `t()`? Not sure. Otherwise RTBC+1 from me.

hocu’s picture

Apparently it's not available: Error: Using $this when not in object context.

nathandentzau’s picture

@hocu FYI $this is not available in a static context, aka a static method on an object. I just tested this locally and looks good. RTBC.

nathandentzau’s picture

Status: Needs review » Reviewed & tested by the community
hocu’s picture

Wonderful! Thanks @nathandentzau and everyone for your great help with this ticket.

hocu’s picture

Assigned: Unassigned » hocu
hocu’s picture

  • a19d99d committed on 8.x-1.x
    Issue #3108828 by hocu, kswamy, scott_euser, nathandentzau, hugronaphor...
hocu’s picture

Status: Reviewed & tested by the community » Fixed
hocu’s picture

Status: Fixed » Closed (fixed)