You are here

function notifications_content_notifications_templates in Notifications 6.4

Implementation of hook_notifications_templates()

File

notifications_content/notifications_content.module, line 480
Subscriptions to content events

Code

function notifications_content_notifications_templates($op, $type = 'all', $language = NULL) {
  switch ($op) {
    case 'help':
      if (strpos($type, 'notifications-event') === 0) {
        $help[] = t('The <em>Header</em> and <em>Footer</em> will be taken from Notification events.');
        $help[] = t('The <em>Digest line</em> will be used when composing Short digests on which each event will be just a line.');
        return $help;
      }
      break;
    case 'info':
      $info = array();
      if ($type == 'all' || $type == 'notifications-event-node') {

        // Generic notifications event
        $info['notifications-event-node'] = array(
          'module' => 'notifications_content',
          'name' => t('Notifications for node events'),
          'description' => t('Defaults for all notifications related to node events.'),
          'fallback' => 'notifications-event',
        );
      }
      if ($type == 'all' || $type == 'notifications-event-node-insert') {
        $info['notifications-event-node-insert'] = array(
          'module' => 'notifications_content',
          'name' => t('Notifications for node creation'),
          'description' => t('Notifications produced when a new node is created.'),
          'fallback' => 'notifications-event-node',
        );
      }
      if ($type == 'all' || $type == 'notifications-event-node-update') {
        $info['notifications-event-node-update'] = array(
          'module' => 'notifications_content',
          'name' => t('Notifications for node updates'),
          'description' => t('Notifications produced when a node is updated.'),
          'fallback' => 'notifications-event-node',
        );
      }
      if ($type == 'all' || $type == 'notifications-event-node-comment') {
        $info['notifications-event-node-comment'] = array(
          'module' => 'notifications_content',
          'name' => t('Notifications for node comments'),
          'description' => t('Notifications produced when a comment is posted to a node.'),
          'fallback' => 'notifications-event-node',
        );
      }
      if ($type == 'digest' || $type == 'notifications-digest-node-nid') {

        // Node group digests, will have specific help text in hook_help()
        $info['notifications-digest-node-nid'] = array(
          'module' => 'notifications_content',
          'name' => t('Groups digests per node'),
          'description' => t('Group of events digested for each node.'),
          'fallback' => 'notifications-digest',
        );
      }
      if ($type == 'digest' || $type == 'notifications-digest-node-type') {
        $info['notifications-digest-node-type'] = array(
          'module' => 'notifications_content',
          'name' => t('Groups digests per node type'),
          'description' => t('Group of events digested for each node type.'),
          'fallback' => 'notifications-digest',
        );
      }
      return $info;
    case 'parts':
      switch ($type) {
        case 'notifications-event-node':
        case 'notifications-event-node-insert':
        case 'notifications-event-node-update':
        case 'notifications-event-node-comment':

          // Some parts will be re-used from 'notifications-event' group
          // So we specify only subject and main message
          return array(
            'subject' => t('Subject'),
            'main' => t('Content'),
            'digest' => t('Digest line'),
          );
        case 'notifications-digest-node-nid':
        case 'notifications-digest-node-type':
          $parts['title'] = t('Group title');
          $parts['closing'] = t('Group footer');
          return $parts;
      }
      break;
    case 'defaults':

      // Event notifications
      switch ($type) {
        case 'notifications-event-node':
        case 'notifications-event-node-update':
          return array(
            'subject' => t('Update for [type-name]: [title]', array(), $language->language),
            'main' => array(
              '[node-teaser]',
              t('Read more [node-url]', array(), $language->language),
            ),
            'digest' => array(
              '[title]',
              t('Read more [node-url]', array(), $language->language),
            ),
          );
        case 'notifications-event-node-insert':
          return array(
            'subject' => t('New [type-name]: [title]', array(), $language->language),
            'main' => array(
              '[node-teaser]',
              t('Read more [node-url]', array(), $language->language),
            ),
            'digest' => array(
              '[title]',
              t('Read more [node-url]', array(), $language->language),
            ),
          );
        case 'notifications-event-node-comment':
          return array(
            'subject' => t('Comment for [type-name]: [title]', array(), $language->language),
            'main' => array(
              t('Comment by [comment-author-name]: [comment-title]', array(), $language->language),
              '[comment-body]',
              t('Read more [comment-url]', array(), $language->language),
            ),
            'digest' => array(
              t('New Comment on [title] by [comment-author-name] titled [comment-title]'),
              t('Read more [comment-url]', array(), $language->language),
            ),
          );
        case 'notifications-digest-node-nid':

          // Define only group title and group footer (closing)
          // The 'closing' statement is typically a 'read more' link
          return array(
            'title' => t('Updates for [type-name]: [title]', array(), $language->language),
            'closing' => t('Read more [node-url]', array(), $language->language),
          );
        case 'notifications-digest-node-type':
          return array(
            'title' => t('New content of type [type-name] has been submitted', array(), $language->language),
            'closing' => '<none>',
          );
      }
      break;
    case 'tokens':
      $args = explode('-', $type) + array(
        2 => '',
        3 => '',
      );
      $tokens = array();

      // These are the token groups that will be used for this module's messages
      if ($args[0] == 'notifications' && $args[2] == 'node') {
        if ($args[1] == 'event') {
          $tokens[] = 'node';
          if ($args[3] == 'comment') {
            $tokens[] = 'comment';
          }
        }
        elseif ($args[1] == 'digest') {
          if ($args[3] == 'nid') {
            $tokens[] = 'node';
          }
          elseif ($args[3] == 'type') {

            // Special format for isolated tokens: array('token type', 'token id').
            // In this case, as messages are digested by node type the only common element will be node-type
            $tokens[] = array(
              'node',
              'type-name',
            );
          }
        }
      }
      return $tokens;
  }
}