You are here

function taxonomy_entity_index_tokens in Taxonomy Entity Index 7

Same name and namespace in other branches
  1. 8 includes/taxonomy_entity_index.tokens.inc \taxonomy_entity_index_tokens()

Implements hook_tokens().

File

./taxonomy_entity_index.tokens.inc, line 50
Token integration for the taxonomy_entity_index module.

Code

function taxonomy_entity_index_tokens($type, $tokens, array $data = array(), array $options = array()) {
  if (!module_exists('token') || _token_module($type, 'terms') != 'taxonomy_entity_index') {

    // We depend on the token_get_entity_mapping() function in token.module.
    return array();
  }
  $replacements = array();
  $sanitize = !empty($options['sanitize']);

  // Entity tokens.
  if (!empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type))) {
    $entity = $data[$type];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'terms':
          $terms = _taxonomy_entity_index_get_terms_array($entity_type, $entity);
          $replacements[$original] = token_render_array($terms, $options);
          break;
      }
    }

    // Chained token relationships.
    if ($terms_tokens = token_find_with_prefix($tokens, 'terms')) {
      if ($terms = _taxonomy_entity_index_get_terms_array($entity_type, $entity)) {
        $replacements += token_generate('array', $terms_tokens, array(
          'array' => $terms,
        ), $options);
      }
    }
  }
  return $replacements;
}