Problem/Motivation

The drupal_set_message() is deprecated in 8.5.0 core https://www.drupal.org/node/2774931

Proposed resolution

replace usage with properly injected services

Remaining tasks

patch, test & commit

Comments

andypost created an issue. See original summary.

andypost’s picture

Issue tags: +Novice
govind.maloo’s picture

Status: Active » Needs review
StatusFileSize
new3.19 KB
chi’s picture

Does that make sense to require Drupal Core 8.5+ in masquerade.info.yml and composer.json files?

andypost’s picture

Status: Needs review » Needs work

@Chi good point! makes a lot of sense

govind.maloo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.49 KB
new255 bytes
chi’s picture

Status: Needs review » Needs work

Btw, the ControllerBase comes with MessengerTrait. So need to inject the messenger service as well as redirect destination.

andypost’s picture

Yep it was my bad in related issue - controller should use redirectDestination property

ivanmaru’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB

There's no need to reinject the Messenger service in the controller's constructor, it already extends the class ControllerBase wich has the MessengerTrait.
Replaced the use of the property with the method messenger() from said MessengerTrait.
ContributionWeekend2019

chi’s picture

+++ b/src/Controller/SwitchController.php
@@ -80,13 +81,13 @@ class SwitchController extends ControllerBase {
+      $this->messenger->addError($error);

$this->messenger property is NULL by default. I think it is better to rely on $this->messanger().

andypost’s picture

Status: Needs review » Needs work

CNW for #10

elaman’s picture

Assigned: Unassigned » elaman

Assigning

elaman’s picture

Assigned: elaman » Unassigned
StatusFileSize
new3.25 KB

Patch addressing #10

elaman’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: replace-drupal-set-message-3018096-13.patch, failed testing. View results

elaman’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: replace-drupal-set-message-3018096-13.patch, failed testing. View results

elaman’s picture

Status: Needs work » Needs review

Tests passed after inconsistently failing, because of random build errors.

hchang’s picture

I can confirm #13 is working who can update this to fixed?

chi’s picture

Status: Needs review » Needs work

#7 needs to be addressed.

neslee canil pinto’s picture

Status: Needs work » Needs review
StatusFileSize
new65.97 KB

Replaced drupal set message with messenger service

chi’s picture

Status: Needs review » Needs work

@Neslee Canil Pinto, the path is 65 KB. Did you upload correct file?

neslee canil pinto’s picture

Status: Needs work » Needs review
StatusFileSize
new3.25 KB

Replaced drupal set message with messenger service

elaman’s picture

@chi it is addressed in #13
@neslee-canil-pinto that patch is an exact copy of the patch #13

chi’s picture

Status: Needs review » Needs work

Patch in #23 is exact like in #13.

chi’s picture

Let's summarize the task.

There is no need to inject messenger service to constructor. The controller extends BaseController which uses MessengerTrait.

However there is a small important detail about accessing the messenger. The trait instantiates the messenger lazily.

public function messenger() {
  if (!isset($this->messenger)) {
    $this->messenger = \Drupal::messenger();
  }
  return $this->messenger;
}

This means you should access the messenger through $this->messenger() method not through $this->messenger property. Given that the whole issue is just about replacing drupal_set_message() with $this->messenger()->addStatus() or $this->messenger()->addError().

elaman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.83 KB

@chi thank you for clarifications

chi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good for me. Thanks.

andypost’s picture

StatusFileSize
new354 bytes

I see no reason in second line, so gonna commit with this change

  • andypost committed ce3400a on 8.x-2.x authored by Elaman
    Issue #3018096 by govind.maloo, Elaman, Neslee Canil Pinto, ivanmaru,...
andypost’s picture

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

Does it needs follow-up to update composer requirements?

Status: Fixed » Closed (fixed)

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