Piwik\
Describes a UI notification.
UI notifications are messages displayed to the user near the top of the screen. Notifications consist of a message, a context (the message type), a priority and a display type.
The context affects the way the message looks, but not how it is displayed.
The display type determines how the message is displayed.
The priority determines where it is shown in the list of all displayed notifications.
Display an error message
$notification = new Notification('My Error Message');
$notification->context = Notification::CONTEXT_ERROR;
Notification\Manager::notify('myUniqueNotificationId', $notification);
Display a temporary success message
$notification = new Notification('Success');
$notification->context = Notification::CONTEXT_SUCCESS;
$notification->type = Notification::TYPE_TOAST;
Notification\Manager::notify('myUniqueNotificationId', $notification);
Display a message near the top of the screen
$notification = new Notification('Urgent: Your password has expired!');
$notification->context = Notification::CONTEXT_INFO;
$notification->type = Notification::TYPE_PERSISTENT;
$notification->priority = Notification::PRIORITY_MAX;
This class defines the following constants:
FLAG_NO_CLEAR
— If this flag is applied, no close icon will be displayed. Note: persistent notifications always have a close
icon. Inherited from Notification
- FLAG_CLEAR
— If this flag is applied, a close icon will be displayed. Inherited from Notification
- TYPE_PERSISTENT
— Notifications of this type will be displayed until the new user explicitly closes the notification. Inherited from Notification
FLAG_NO_CLEAR
See $flags.
FLAG_CLEAR
See $flags.
TYPE_PERSISTENT
The notifications will display even if the user reloads the page.
This class defines the following properties:
$title
— The notification title.$message
— The notification message.$flags
— Contains extra display options.$type
— The notification's display type.$context
— The notification's context (message type).$priority
— The notification's priority.$raw
— If true, the message will not be escaped before being outputted as HTML.$title
The notification title. The title is optional and is displayed directly before the message content.
string
value.$message
The notification message. Must be set.
string
value.$flags
Contains extra display options.
Usage: $notification->flags = Notification::FLAG_BAR | Notification::FLAG_FOO
.
int
value.$type
The notification's display type. See TYPE_*
constants in Notification.
string
value.$context
The notification's context (message type). See CONTEXT_*
constants in Notification.
A notification's context determines how it will be styled.
string
value.$priority
The notification's priority. The higher the priority, the higher the order. See PRIORITY_*
constants in Notification to see possible priority values.
int
value.$raw
If true, the message will not be escaped before being outputted as HTML. If you set this to
true
, make sure you escape text yourself in order to avoid XSS vulnerabilities.
bool
value.The class defines the following methods:
__construct()
— Constructor.hasNoClear()
— Returns 1
if the notification will be displayed without a close button, 0
if otherwise.getPriority()
— Returns the notification's priority.__construct()
Constructor.
$message
(string
) —
The notification message.Exception
— If the message is empty.hasNoClear()
Returns 1
if the notification will be displayed without a close button, 0
if otherwise.
int
—
1
or 0
.getPriority()
Returns the notification's priority. If no priority has been set, a priority will be set based on the notification's context.
int
value.