Part of #1839338: [meta] Remove drupal_set_*() drupal_add_*() in favour of #attached/response for out-of-band stuff.

We need to:

  1. Come up with an alternate solution for drupal_set_message().
  2. Deprecate drupal_set_message().
  3. Convert core to use the new method.
  4. Remove drupal_set_message().

Comments

xjm’s picture

Priority: Critical » Major

Downgrading to major per @catch:

drupal_set_messsage() is a funny one. Since that adds messages to $_SESSION it's not actually that bad if everything happens in a single request, messages aren't page assets like most other drupal_set_*() stuff.

However in a real *SI situation the message collection via checking $_SESSION isn't guaranteed to run. So that one doesn't feel like a release blocker but could use some discussion.

xjm’s picture

We can probably treat messages like contextual links, the new comments marker, etc. and add them asynchronously?

xjm’s picture

Issue tags: -Approved API change

Premature tagging.

Crell’s picture

My original hope was to use Symfony Flash messages on the request, as they were beefed up to be feature-parity with drupal_set_message() back in Symfony 2.1 at our request. That however has been effectively blocked on #1858196: [meta] Leverage Symfony Session components for closing in on 2 years. :-/ (I think at the moment the remaining issues are testbot issues, not code issues, so I don't know how to fix those.)

catch’s picture

@Crell that's not very relevant to the parent issue.

Both drupal_set_message() and Symfony flash messages use the $_SESSION to store messages. Last time I looked I was unable to find an implementation for collection and display of flash messages in Symfony 2.

It's the collection and display of messages that can cause problems if you have messages set in AJAX or ESI requests since they might complete after the 'main' request, or there might not be a 'main' request in PHP at all.

Session storage is by definition global so it's not the same problem as CSS/JS assets, the page title etc where that information would just get lost, the worst that happens at the moment is that a message gets shown on the next request instead of the current one.

@xjm yes just collecting the messages via yet another request (which checks and clears out $_SESSION) would work fine for this, I'm not we want to do that in core though, rather make sure it's doable from contrib.

Crell’s picture

With #2068471: Normalize Controller/View-listener behavior with a Page object, we'd be clearly splitting the body from the html rendering. One thing that may let us do is push messages into JS settings, because we're certain that the page has been reduced to a string by that point so any processing involved in that has happened already. Then on render, pull them out of there and render client-side into a known div ID in the page.

Then it's natural for Ajax cases to just turn any pending messages into more Ajax commands, which can get rendered in the same way.

Downside: this requires JS for any messages to be displayed. Pages without messages wouldn't need JS, but we'd need at least a little for messages to work. I don't know of an alternative there. (And I am not convinced that's a show-stopper in 2014.)

Xano’s picture

Issue summary: View changes

I just opened #2278383: Create an injectible service for drupal_set_message(), which may or may not address some of your concerns.

xjm’s picture

Dries’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed

As a normal task, per #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?, I think this should be postponed to 8.1.x. Merely improving testability is not a good enough reason to get this included this late in the release cycle. However, if #2073817: [META] Remove drupal_set_message() identifies an important cacheability/performance bug that requires this to be done, then we can move it back to the 8.0.x queue.

effulgentsia’s picture

Version: 8.1.x-dev » 8.0.x-dev
Status: Postponed » Active

Dries wrote #9 while on a call with me, so I happen to know that he intended it for #2278383: Create an injectible service for drupal_set_message(), so reverting issue attributes of this meta issue.

Though based on the comment, this issue will also get postponed to 8.1.x unless a major bug requires it to be done. But moving it back to the 8.0.x queue for now, to allow for some discussion on whether such a bug exists.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

valthebald’s picture

Version: 8.1.x-dev » 8.2.x-dev
Issue tags: +Triaged for D8 major current state, +neworleans2016

I am triaging the issue as a part of DrupalCon NOLA.
drupal_set_message() still exists in the code, and is widely used, so the issue still present.
As a part of the solution, should drupal_set_message() be removed as deprecated in 8.x, its usage removed, and function itself be removed before 9.0.0?

catch’s picture

Status: Active » Postponed

Postponed on #2278383: Create an injectible service for drupal_set_message() at this point. At the moment there's nothing to deprecate it for.

xjm’s picture

Thanks @valthebald for helping triage majors at the sprint; updating to add triage credit.

xjm’s picture

Status: Postponed » Closed (duplicate)
Related issues: +#2607260: [meta] Core deprecation message introduction, contrib testing etc.

@webchick, @Cottser, @alexpott, @catch, @effulgentsia, and I agreed to close this in favor of #2278383: Create an injectible service for drupal_set_message() and potentially #2347287: Provide a trait for setting messages. Those issues will deprecate drupal_set_message(), and then removal of the deprecated code would happen as part of the preparation for 9.x in #2607260: [meta] Core deprecation message introduction, contrib testing etc..

subramani.msc2011’s picture

System messages are stored in a Symfony Flashbag, so there is no need to hack session variables, which can change from version to version. In Drupal 8.5 a new Messenger service was introduced to encapsulate the symfony flash bag and you can delete messages with deleteAll():

\Drupal::messenger()->deleteAll();