You are here

function _subscriptions_content_node_options in Subscriptions 7

Same name and namespace in other branches
  1. 5.2 subscriptions_content.module \_subscriptions_content_node_options()
  2. 6 subscriptions_content.module \_subscriptions_content_node_options()
  3. 2.0.x subscriptions_content/subscriptions_content.module \_subscriptions_content_node_options()

Implementation of hook_node_options(), subhook of hook_subscriptions().

This is called by subscriptions_ui_node_form() in subscriptions_ui.module.

Parameters

object $account:

object $node:

Return value

array

See also

subscriptions_ui_node_form()

File

./subscriptions_content.module, line 118
Subscriptions to content events

Code

function _subscriptions_content_node_options($account, $node) {

  // Default node, field are the first three indexes, but they can be overridden in params
  // Thread
  $options = array();

  /** @var $statics array */
  $statics = variable_get('subscriptions_static_content_types', array());
  if (!in_array($node->type, $statics, TRUE)) {
    $options['nid'][] = array(
      'name' => t('Subscribe to this page'),
      'params' => array(
        'module' => 'node',
        'field' => 'nid',
        'value' => $node->nid,
      ),
      'link' => 'node/' . $node->nid,
    );
    $options['nid']['weight'] = -4;
  }

  /** @var $unlisteds array */
  $unlisteds = variable_get('subscriptions_unlisted_content_types', array());
  if (user_access('subscribe to content types', $account)) {
    $unlisted_tag = '';
    if (in_array($node->type, $unlisteds, TRUE)) {
      if (user_access('subscribe to all content types', $account)) {
        $unlisted_tag = ' ' . SUBSCRIPTIONS_UNAVAILABLE;
      }
      else {
        return $options;
      }
    }

    // Content type
    $type_name = node_type_get_name($node->type);
    if ($type_name) {
      $options['type'][] = array(
        'name' => t('To %type content', array(
          '%type' => $type_name,
        )) . $unlisted_tag,
        'params' => array(
          'module' => 'node',
          'field' => 'type',
          'value' => $node->type,
        ),
        'link' => 'type/' . $node->type,
      );

      // Content type and author
      $options['type'][] = array(
        'name' => t('To %type content by %name', array(
          '%type' => $type_name,
          '%name' => format_username(user_load($node->uid)),
        )) . $unlisted_tag,
        'params' => array(
          'module' => 'node',
          'field' => 'type',
          'value' => $node->type,
          'author_uid' => $node->uid,
        ),
        'link' => 'type/' . $node->type . '/' . $node->uid,
      );
      $options['type']['weight'] = -2;
    }
  }
  return $options;
}