You are here

function _subscriptions_content_node_options in Subscriptions 2.0.x

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. 7 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/subscriptions_content.module, line 120
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 = [];

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

  /** @var array $unlisteds */
  $unlisteds = variable_get('subscriptions_unlisted_content_types', []);
  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'][] = [
        'name' => t('To %type content', [
          '%type' => $type_name,
        ]) . $unlisted_tag,
        'params' => [
          'module' => 'node',
          'field' => 'type',
          'value' => $node->type,
        ],
        'link' => 'type/' . $node->type,
      ];

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