You are here

function notifications_content_notifications in Notifications 6.4

Same name and namespace in other branches
  1. 5 notifications_content/notifications_content.module \notifications_content_notifications()
  2. 6 notifications_content/notifications_content.module \notifications_content_notifications()
  3. 6.2 notifications_content/notifications_content.module \notifications_content_notifications()
  4. 6.3 notifications_content/notifications_content.module \notifications_content_notifications()
  5. 7 notifications_content/notifications_content.module \notifications_content_notifications()

Implementation of hook_notifications()

File

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

Code

function notifications_content_notifications($op) {
  switch ($op) {
    case 'subscription types':

      // Some types may be globally disabled (for all content types), mark as such
      $disabled = !variable_get('notifications_content_per_type', 0);
      $types['thread'] = array(
        'event_type' => 'node',
        'object_type' => 'node',
        'title' => t('Thread'),
        'access' => 'subscribe to content',
        'page callback' => 'notifications_content_page_thread',
        'user page' => 'user/%user/notifications/thread',
        'fields' => array(
          'nid',
        ),
        'description' => t('Subscribe to all changes and comments for a thread.'),
        'name callback' => 'notifications_content_subscription_name',
      );
      $types['nodetype'] = array(
        'event_type' => 'node',
        'object_type' => 'node',
        'title' => t('Content type'),
        'access' => 'subscribe to content type',
        'page callback' => 'notifications_content_page_nodetype',
        'user page' => 'user/%user/notifications/nodetype',
        'fields' => array(
          'type',
        ),
        'description' => t('Subscribe to all content of a given type.'),
        'name callback' => 'notifications_content_subscription_name',
      );
      $types['author'] = array(
        'event_type' => 'node',
        'object_type' => 'user',
        'title' => t('Author'),
        'access' => 'subscribe to author',
        'page callback' => 'notifications_content_page_author',
        'user page' => 'user/%user/notifications/author',
        'fields' => array(
          'author',
        ),
        'description' => t('Subscribe to all content submitted by a user.'),
        'name callback' => 'notifications_content_subscription_name',
      );

      // This is a complex type, combining two fields
      $types['typeauthor'] = array(
        'event_type' => 'node',
        'object_type' => array(
          'node',
          'user',
        ),
        // This makes sense per node and per user
        'title' => t('Content type by author'),
        'access' => 'subscribe to content type and author',
        'page callback' => 'notifications_content_page_typeauthor',
        'user page' => 'user/%user/notifications/typeauthor',
        'fields' => array(
          'author',
          'type',
        ),
        'description' => t('Subscribe to all content of a given type submitted by a user.'),
        'name callback' => 'notifications_content_subscription_name',
      );
      return $types;
    case 'subscription fields':

      // Information about available fields for subscriptions
      // - format callback => will be used to convert the value into a displayable output
      // - value callback => will be used to convert autocomplete name into field value
      // - autocomplete path => path for autocomplete field
      // - options callback / arguments => used to produce a drop down field
      $fields['nid'] = array(
        'name' => t('Node'),
        'field' => 'nid',
        'type' => 'int',
        'object_type' => 'node',
      );
      $fields['author'] = array(
        'name' => t('Author'),
        'field' => 'author',
        'type' => 'int',
        'object_type' => 'user',
      );
      $fields['type'] = array(
        'name' => t('Node type'),
        'field' => 'type',
        'type' => 'string',
        'options callback' => 'notifications_content_types_callback',
      );
      return $fields;
    case 'object types':

      // Define object types for use by events and subscriptions
      // Node and user are defined in the main notifications module
      $types['comment'] = array(
        'name' => t('Comment'),
        'key_field' => 'cid',
        'load callback' => 'notifications_content_comment_load',
        'format callback' => 'notifications_content_comment_cid2title',
        'access callback' => 'notifications_content_comment_access',
      );
      return $types;
    case 'event types':

      // Node inserts are not grouped by node but all together. The digest will look like:
      //   New content has been submitted
      //   - Story Title1 by Author1
      //   - Event Title2 by Author2
      $types['node-insert'] = array(
        'type' => 'node',
        'action' => 'insert',
        'name' => t('New content of type [type-name] has been submitted'),
        'line' => t('[type-name] [title] by [author-name]'),
        'digest' => array(
          'node',
          'type',
        ),
        'description' => t('Node creation'),
        'template' => 'notifications-event-node-insert',
      );

      // These other events are grouped for each node. The digest will look like:
      //   Story: Title of the story
      //   - The story has been updated
      //   - New comment by User: Comment title
      $types['node-update'] = array(
        'type' => 'node',
        'action' => 'update',
        'name' => t('[type-name]: [title]'),
        'line' => t('The [type-name] has been updated'),
        'digest' => array(
          'node',
          'nid',
        ),
        'description' => t('Node update'),
        'template' => 'notifications-event-node-update',
      );
      $types['node-comment'] = array(
        'type' => 'node',
        'action' => 'comment',
        'name' => t('[type-name]: [title]'),
        'line' => t('New comment by [comment-author-name]: [comment-title]'),
        'digest' => array(
          'node',
          'nid',
        ),
        'description' => t('Node comment'),
        'template' => 'notifications-event-node-comment',
      );
      return $types;
    case 'event classes':
      return array(
        'node' => t('Node'),
      );
    case 'event actions':
      return array(
        'insert' => t('Creation'),
        'update' => t('Update'),
        'comment' => t('Comment'),
      );
  }
}