You are here

function nodequeue_node_links in Nodequeue 7.2

Same name and namespace in other branches
  1. 7.3 nodequeue.module \nodequeue_node_links()

Returns an array of nodequeue links for a node.

2 calls to nodequeue_node_links()
nodequeue_handler_field_links::render in includes/views/nodequeue_handler_field_links.inc
Render the field.
nodequeue_node_view in ./nodequeue.module
Implements hook_node_view().

File

./nodequeue.module, line 1884
Maintains queues of nodes in arbitrary order.

Code

function nodequeue_node_links($node) {
  $links = array();
  if (variable_get('nodequeue_links', FALSE) && user_access('manipulate queues')) {
    $queues = nodequeue_load_queues_by_type($node->type, 'links');
    $subqueues = nodequeue_get_subqueues_by_node($queues, $node);
    if (empty($subqueues)) {
      return;
    }

    // resort the subqueues to retain consistent ordering:
    ksort($subqueues);

    // Due to caching, we can accidentally get positions leftover
    // from previous iterations on teaser list pages, so we must
    // remove any existing positions here.
    foreach ($subqueues as $id => $subqueue) {
      unset($subqueues[$id]->position);
    }
    if (!module_exists('translation')) {
      nodequeue_set_subqueue_positions($subqueues, $node->nid);
    }
    foreach ($subqueues as $subqueue) {
      $queue = $queues[$subqueue->qid];
      $id = nodequeue_get_content_id($queue, $node);
      if (module_exists('translation')) {
        $subqueue = array(
          $subqueue->sqid => $subqueue,
        );
        nodequeue_set_subqueue_positions($subqueue, $id);
        $subqueue = array_shift($subqueue);
      }
      $query_string = nodequeue_get_query_string($id, TRUE);
      $class = 'nodequeue-ajax-toggle nodequeue-toggle-q-' . $queue->qid . ' nodequeue-toggle-sq-' . $subqueue->sqid . ' nodequeue-toggle-ref-' . $subqueue->reference;
      if (!isset($subqueue->position)) {
        $links[$class] = array(
          'title' => nodequeue_title_substitute($queue->link, $queue, $subqueue),
          'href' => "nodequeue/{$queue->qid}/add-node/{$subqueue->sqid}/{$id}",
          'attributes' => array(
            'class' => array(
              $class . ' toggle-add',
            ),
          ),
          'query' => $query_string,
          'purl' => array(
            'disabled' => TRUE,
          ),
        );
      }
      elseif ($queue->link_remove) {
        $links[$class] = array(
          'title' => nodequeue_title_substitute($queue->link_remove, $queue, $subqueue),
          'href' => "nodequeue/{$queue->qid}/remove-node/{$subqueue->sqid}/{$id}",
          'attributes' => array(
            'class' => array(
              $class . ' toggle-remove',
            ),
          ),
          'query' => $query_string,
          'purl' => array(
            'disabled' => TRUE,
          ),
        );
      }
    }
    drupal_add_js(drupal_get_path('module', 'nodequeue') . '/nodequeue.js');
    drupal_add_css(drupal_get_path('module', 'nodequeue') . '/nodequeue.css');
  }
  return $links;
}