You are here

function notifications_messaging in Notifications 5

Same name and namespace in other branches
  1. 6.4 notifications.module \notifications_messaging()
  2. 6 notifications.module \notifications_messaging()
  3. 6.2 notifications.module \notifications_messaging()
  4. 6.3 notifications.module \notifications_messaging()
  5. 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 741
Notifications module

Code

function notifications_messaging($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg4 = NULL) {
  switch ($op) {
    case 'message groups':

      // Generic notifications event
      $info['notifications-event'] = array(
        'module' => 'notifications',
        'name' => t('Notifications event'),
        'description' => t('Fallback for all Notifications events.'),
      );
      $info['notifications-digest'] = array(
        'module' => 'notifications',
        'name' => t('Notifications digest'),
        'description' => t('Common parts for Notifications digests.'),
      );
      return $info;
    case 'message keys':
      $type = $arg1;
      switch ($type) {
        case 'notifications-event':

          // Event notifications
          return array(
            'subject' => t('Subject for event notifications'),
            'header' => t('Header for event notifications'),
            'main' => t('Content for event notifications'),
            'footer' => t('Footer for event notifications'),
          );
        case 'notifications-digest':
          return array(
            'subject' => t('Subject for digested notifications'),
            'header' => t('Header for digested notifications'),
            'footer' => t('Footer for digested notifications'),
          );
      }
      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(
          'global',
          'subscription',
          'user',
        );
        if ($type[1] == 'event') {
          $tokens[] = 'event';
        }
      }
      return $tokens;
  }
}