function notifications_messaging in Notifications 6
Same name and namespace in other branches
- 5 notifications.module \notifications_messaging()
- 6.4 notifications.module \notifications_messaging()
- 6.2 notifications.module \notifications_messaging()
- 6.3 notifications.module \notifications_messaging()
- 7 notifications.module \notifications_messaging()
Implementation of hook_messaging()
This hook provides information about the mensaje templates this module uses and related tokens.
Depending on $op, this hook takes different parameters and returns different pieces of information:
- 'message groups' Get array of message groups, each of which will have one or more keys for different templates Each group should have a unique key, so it should start with the module name
- 'message keys' Get message template parts for a given group ($arg1) Return array of key => name for each part
- 'messages' Get default message templates for a given group ($arg1). It should return default texts, indexed by message key that will be the default templates These templates may be edited on the 'Messaging templates' page
- 'tokens' Get available tokens for a given message group and key ($arg1). Return array of token keys that will be available for this message templates The tokens themselves may be default tokens (provided by token module) or we can add new tokens implementing hook_token_list() and hook_token_value()
Parameters
$op: Operation, type of information to retrieve
$arg1, $arg2...: Different parameters depending on $op
File
- ./
notifications.module, line 1061 - Notifications module
Code
function notifications_messaging($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg4 = NULL) {
switch ($op) {
case 'message types':
$info['notifications'] = array(
'name' => t('Notifications'),
'description' => t('Messages coming from user subscriptions and system events'),
);
return $info;
case 'message groups':
// Generic notifications event
$info['notifications-event'] = array(
'module' => 'notifications',
'name' => t('Notifications event'),
'description' => t('Common parts for all Notifications messages for a single event. This is useful for defining a common header and/or footer for all these messages.'),
);
$info['notifications-digest'] = array(
'module' => 'notifications',
'name' => t('Notifications digest'),
'description' => t('Depending on your settings for each Send interval, Notifications may be digested, this is grouped and summarized in a single message. These are the common parts for Notifications digests.'),
);
return $info;
case 'message keys':
$type = $arg1;
switch ($type) {
case 'notifications-event':
// Event notifications
return array(
'subject' => t('Subject'),
'header' => t('Header'),
'main' => t('Content'),
'footer' => t('Footer'),
);
case 'notifications-digest':
return array(
'subject' => t('Subject'),
'header' => t('Header'),
'main' => t('Line for digested events'),
'footer' => t('Footer'),
);
}
break;
case 'messages':
$type = $arg1;
// Event notifications
if ($type == 'notifications-event') {
return array(
'subject' => t('Event notification for [user] from [site-name]'),
'header' => t("Greetings [user],"),
'main' => t("A item to which you are subscribed has been updated"),
'footer' => array(
t('This is an automatic message from [site-name]'),
t('To manage your subscriptions, browse to [subscriptions-manage]'),
t('You can unsubscribe at [unsubscribe-url]'),
),
);
}
// Digested messages
if ($type == 'notifications-digest') {
return array(
'subject' => t('[site-name] subscription update for [user]'),
'header' => t("Greetings, [user].\n\nThese are your messages"),
'main' => t("A [type] has been updated: [title]\n\n[event_list]"),
'footer' => array(
t('This is an automatic message from [site-name]'),
t('To manage your subscriptions, browse to [subscriptions-manage]'),
),
);
}
break;
case 'tokens':
$type = explode('-', $arg1);
$tokens = array();
// These are the token groups that will be used for this module's messages
if ($type[0] == 'notifications') {
$tokens = array(
'subscription',
'user',
);
if ($type[1] == 'event') {
$tokens[] = 'event';
}
}
return $tokens;
case 'method update':
// A messaging method has been disabled ($arg1) and replaced by the new one ($arg2)
// Update subscriptions
db_query("UPDATE {notifications} SET send_method = '%s' WHERE send_method = '%s'", $arg2, $arg1);
// Purge notifications queue, we may lost some notifications but it's the safest option.
db_query("DELETE FROM {notifications_queue} WHERE send_method = '%s'", $arg1);
break;
}
}