You are here

function notifications_messaging_template in Notifications 6.3

Implementation of hook_messaging_template()

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 $type 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

$type: Template type

File

./notifications.module, line 1127
Notifications module

Code

function notifications_messaging_template($op, $type = NULL, $langcode = NULL) {
  switch ($op) {
    case 'types':
      $info['notifications'] = array(
        'title' => t('Notifications', array(), $langcode),
        'description' => t('Messages coming from user subscriptions and system events', array(), $langcode),
      );
      return $info;
    case 'templates':

      // Generic notifications event
      $info['notifications-event'] = array(
        'module' => 'notifications',
        'type' => 'notifications',
        'title' => t('Notifications event', array(), $langcode),
        'digest' => 'notifications-digest',
        '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.', array(), $langcode),
      );
      return $info;
    case 'keys':
      if ($type == 'notifications-event') {
        return array(
          'subject' => t('Subject', array(), $langcode),
          'header' => t('Header', array(), $langcode),
          'main' => t('Content', array(), $langcode),
          'footer' => t('Footer', array(), $langcode),
        );
      }
      elseif (strpos($type, 'notifications-event') === 0 || strpos($type, 'notifications-content') === 0) {
        return array(
          'subject' => t('Subject', array(), $langcode),
          'header' => t('Header', array(), $langcode),
          'main' => t('Content', array(), $langcode),
          'footer' => t('Footer', array(), $langcode),
        );
      }
      break;
    case 'defaults':

      // Event notifications
      if ($type == 'notifications-event') {
        return array(
          'subject' => t('Event notification for [user] from [site-name]', array(), $langcode),
          'header' => t("Greetings [user],", array(), $langcode),
          'main' => t("A item to which you are subscribed has been updated", array(), $langcode),
          'footer' => array(
            t('This is an automatic message from [site-name]', array(), $langcode),
            t('To manage your subscriptions, browse to [subscriptions-manage]', array(), $langcode),
            t('You can unsubscribe at [unsubscribe-url]', array(), $langcode),
          ),
        );
      }
      break;
    case 'tokens':
      $keys = explode('-', $type);
      $tokens = array();

      // These are the token groups that will be used for this module's messages
      if ($keys[0] == 'notifications') {
        $tokens = array(
          'subscription',
          'user',
        );
        if ($keys[1] == 'event') {
          $tokens[] = 'event';
        }
      }
      return $tokens;
    case 'token info':

      // Get names for tokens
      $tokens['global'] = array(
        'name' => t('Global'),
        'description' => t('Site wide global tokens.'),
      );
      $tokens['subscription'] = array(
        'name' => t('Subscription'),
        'description' => t('Subscription that caused the notification.'),
      );
      $tokens['user'] = array(
        'name' => t('User'),
        'description' => t('User receiving the notification.'),
      );
      $tokens['event'] = array(
        'name' => t('Event'),
        'description' => t('Event causing the notification.'),
      );
      return $tokens;
  }
}