You are here

function _subscriptions_taxonomy_node_options in Subscriptions 7

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

Implements _hook_node_options(), subhook of hook_subscriptions().

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

Parameters

$account:

$node:

Return value

array|null

See also

subscriptions_ui_node_form()

File

./subscriptions_taxonomy.module, line 90
Subscriptions to taxonomy terms.

Code

function _subscriptions_taxonomy_node_options($account, $node) {
  global $user;
  if (!user_access('subscribe to taxonomy terms')) {
    return NULL;
  }
  $options = array();
  $taxonomy_fields = field_read_fields(array(
    'type' => 'taxonomy_term_reference',
  ));

  /** @var $vids_to_omit array */
  $vids_to_omit = variable_get('subscriptions_omitted_taxa', array());
  foreach ($taxonomy_fields as $field_key => $field) {
    if (isset($node->{$field_key})) {
      if ($items = field_get_items('node', $node, $field_key)) {
        foreach ($items as $item) {
          $term = NULL;
          $hidden = array();
          $unavailable = '';
          if (!empty($item['taxonomy_term'])) {
            $term = $item['taxonomy_term'];
          }
          elseif (!empty($item['tid'])) {
            $term = taxonomy_term_load($item['tid']);
            if ($term->vid != variable_get('forum_nav_vocabulary', 0)) {

              // The field is hidden for this content type.
              if ($user->uid == 1) {
                $unavailable = ' ' . SUBSCRIPTIONS_UNAVAILABLE;
              }
              else {
                $hidden = array(
                  '#access' => FALSE,
                );
              }
            }
          }
          if ($term) {
            if (!in_array($term->vid, $vids_to_omit)) {
              $tid = $term->tid;
              $options['tid'][] = array(
                'name' => t('To content in %term', array(
                  '%term' => $term->name,
                )) . $unavailable,
                'params' => array(
                  'module' => 'node',
                  'field' => 'tid',
                  'value' => $tid,
                ),
                'link' => 'taxa/' . $tid,
              ) + $hidden;
              $options['tid'][] = array(
                'name' => t('To content in %term by %name', array(
                  '%term' => $term->name,
                  '%name' => format_username(user_load($node->uid)),
                )) . $unavailable,
                'params' => array(
                  'module' => 'node',
                  'field' => 'tid',
                  'value' => $tid,
                  'author_uid' => $node->uid,
                ),
                'link' => 'taxa/' . $tid . '/' . $node->uid,
              ) + $hidden;
              if ($field_key == 'taxonomy_forums') {

                // Move forum items to the top.
                array_unshift($options['tid'], array_pop($options['tid']));
                array_unshift($options['tid'], array_pop($options['tid']));
              }
              $options['tid']['weight'] = -1;
            }
          }
        }
      }
    }
  }
  return $options;
}