You are here

function freelinking_nid_callback in Freelinking 7.3

Same name and namespace in other branches
  1. 6.3 plugins/freelinking_nid.inc \freelinking_nid_callback()

Replacement callback for nid plugin.

Resolve $target into a link to the node or display failure.

Return value

an array with node properties to build the link.

1 string reference to 'freelinking_nid_callback'
freelinking_nid.inc in plugins/freelinking_nid.inc

File

plugins/freelinking_nid.inc, line 27

Code

function freelinking_nid_callback($target, $plugin) {
  $node_cache_nid =& drupal_static(__FUNCTION__ . '_node_cache', array());

  // Check if we already loaded this node.
  $nid = $target['dest'];
  $nodes =& drupal_static(__FUNCTION__, array());
  if (in_array($nid, $nodes)) {

    // Return TRUE to avoid infinite recursion.
    $key = array_search($nid, $node_cache_nid['nid']);
    $value = array(
      $target['text'],
      'node/' . $nid,
      array(
        'attributes' => array(
          'title' => $target['tooltip'],
        ),
      ),
    );
    return $value;
  }

  // New node to process. Cache it at the end.
  $node = node_load($nid);
  if ($node) {
    if (node_access('view', $node)) {
      $title = $target['text'] ? $target['text'] : $node->title;
      $tooltip = $target['tooltip'] ? $target['tooltip'] : $plugin['tip'];
      $value = array(
        check_plain($title),
        'node/' . $nid,
        array(
          'attributes' => array(
            'title' => $tooltip,
          ),
        ),
      );

      // Add the nid to the list of cached nodes.
      $nodes[] = $nid;
      $node_cache_nid['nid'][] = $node->nid;
    }
  }
  if (!isset($value)) {
    $value = array(
      'failover' => 'error',
      'message' => t('Invalid Node ID “!nid”', array(
        '!nid' => $nid,
      )),
    );
  }
  return $value;
}