You are here

function nodehierarchy_tokens in Node Hierarchy 7.4

Same name and namespace in other branches
  1. 7.2 nodehierarchy.tokens.inc \nodehierarchy_tokens()

Implements hook_tokens().

File

./nodehierarchy.tokens.inc, line 34
token integration functions for nodehierarchy.module

Code

function nodehierarchy_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
    $language_code = $options['language']->language;
  }
  else {
    $language_code = NULL;
  }
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $parent_node = NULL;
    $node = $data['node'];

    // Load the parent node if we're going to need any parent tokens.
    $hierarchy_tokens = token_find_with_prefix($tokens, 'nodehierarchy');
    if ($hierarchy_tokens) {
      $parent_node = nodehierarchy_get_node_parent_primary_node($node);
    }
    foreach ($hierarchy_tokens as $name => $original) {

      // Chained token relationships.
      if ($parent_node && ($parent_tokens = token_find_with_prefix($hierarchy_tokens, 'parent'))) {
        $replacements += token_generate('node', $parent_tokens, array(
          'node' => $parent_node,
        ), $options);
      }
    }
  }
  return $replacements;
}