Toastr
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
The Toastr module provides an API that implements the
Toastr.js library. Toastr is a Javascript library for Gnome / Growl type non-blocking notifications. jQuery is required. The goal is to create a simple core library that can be customized and extended.
The module works by polling the server for new messages, and displaying them as needed.
To have messages displayed, just implement hook_toastr_toast(). You get 2 parameters:
- the current user
- the timestamp from the js polling function
/**
* Implements hook_toastr_toast().
*/
function hook_toastr_toast($account, $timestamp) {
$toast = array(
'type' => 'info'
'message' => t('A message to be displayed.'),
);
$toasts[] = $toast;
$toast = array(
'type' => 'success'
'message' => t("@name is on a toast!", array('@name' => format_username($account)));
);
$toasts[] = $toast;
return $toasts;
}
You can also alter toastr messages before they are sent to the browser:
/**
* Implements hook_toastr_toasts_alter().
**/
function example_toastr_toasts_alter(&$toasts, $account, $timestamp) {
// Do something with the yummy toast.
foreach ($toasts as $key => $toast) {
// Prevent toasts from showing to anonymous users.
if ($account->uid == 0) {
unset($toasts[$key]);
}
}
}
Implementation
This module will do nothing on its own. You will need to implement the above hooks in a custom module in order for anything to happen, or enable one of the included sub-modules.
Included Sub-Modules
Toastr Message
Included in the main project is a sub-module for the Message Stack. The sub-module can act as an example module as well as be used on its own to turn Message entities into Toastr notifications.
Toastr Database Log
This sub-module will display database log messages via Toastr. You can select what message severity levels are displayed.
