Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 1.9.4, 2.0
-
Fix Version/s: STABLE backlog
-
Component/s: General
-
Labels:
-
Affected Branches:MOODLE_19_STABLE, MOODLE_20_STABLE
Description
I have found that recently every time I code a block or a module I end up writing up some sort of notification system to inform the user of errors or to inform the user that something worked successfully.
So, I thought that a standard API would be nice to have because I have noticed that other modules are also having to create custom code for informing the user of what has happened. Also, by having a standard API, the look and feel of Moodle will be more singular.
The proposed API has a method for setting any number of messages. These messages are stored in the session to allow for calling a redirect before printing the message. And of course, the API has a method for printing all of the messages. All messages are printed with notify().
Note: The function for printing the messages could even be called in the theme header or in print_header so that all messages are printed in the same location.
Here is the PHPdoc of the two functions:
/**
- Sets a message to be printed. Messages are printed
- by calling {@link print_messages()}.
* - @uses $SESSION
- @param string $message The message to be printed
- @param string $class Class to be passed to {@link notify()}. Usually notifyproblem or notifysuccess.
* @param string $align Alignment of the message
* @return boolean
**/
function set_message($message, $class="notifyproblem", $align='center')
/**
* Print all set messages.
*
* See {@link set_message()} for setting messages.
*
* Uses {@link notify()} to print the messages.
* - @uses $SESSION
- @return boolean
**/
function print_messages()
Attaching the code.