Hi all,
As you may be aware I am the component lead for the Moodle forum.
One of my personal bug-bears in mod_forum is the fact that, after every post, you are redirected to a page informing you that you've just posted before you are then redirected back to the forum index.
This is poor for user experience because workflow is interrupted and the user distracted, and the message is only displayed for a short period (which may not be long enough).
You are redirected to this page purely so that we can display a message because we have no way of storing those messages from one page to the next (without all sorts of nasty hacks like adding the message or some metadata about the message to the URL).
I've put together a proof-of-concept whereby we can store these kinds of messages in the user session such that they can be displayed on the subsequent page load. I've also applied these to all calls redirect() where the headers have not yet been sent, and have added an additional parameter to redirect() to let you specify the type of message being displayed. Previously redirect() only supported 'notification_redirect' which was rendered as a bootstrap alert. It is now possible to specify the constants for success, info, warning, and error.
Because of existing naming conflicts (message = Moodle messaging; notificaiton = JS dialogues; and a related but different renderable), I have opted to name these `flashes`.
I have also added a public interface to the flash system:
\core\flash::add($message, $level);
With helpers for each level:
\core\flash::success($message); \core\flash::info($message); \core\flash::warning($message); \core\flash::error($message);
These can be combined with a JS API to both display new messages, and to fetch and render messages currently in the session:
require(['core/flash'], function(flash) { // Fetch messages currently in the session and display them. flash.fetchFlashes(); // Add a new message to the display (without storing it in the session). flash.addFlash({ message: 'Example message', type: 'success' }); });
The flashes generated here are instances of the \core\output\notification renderable, which has also been updated as part of this change to add sanity. The output of these is provided by a set of mustache templates which can be modified by themes.
I'm aware that some will dislike the name - if you have a better suggestion, I'm all ears. Note that `messages` is used by other sub-systems and would lead to more confusion, and that `notification` is also doubled up with two different uses already. The term `flash` is used by Symfony and derivatives and does accurately describe the nature of the messages - e.g. that they are flashed up to the user once, and then removed from the queue.
This is still a work in progress, but I wanted to share my current work and start getting any feedback that others may have.
The work on this feature is under MDL-30811 where a working prototype is available for testing.
Cheers,
Andrew