You are here

function taxonomy_machine_name_tokens_alter in Taxonomy Machine Name 7

Implements hook_tokens_alter().

File

./taxonomy_machine_name.token.inc, line 22
Taxonomy Machine Name Token Module File.

Code

function taxonomy_machine_name_tokens_alter(array &$replacements, array $context) {
  if (isset($context['tokens']['machine-name']) && ($token = $context['tokens']['machine-name'])) {
    $term = FALSE;
    $sanitize = !empty($options['sanitize']);
    if ($context['type'] == 'term') {
      if (isset($context['data']['term'])) {
        $term = $context['data']['term'];
      }
      elseif (isset($context['data']['taxonomy_term'])) {
        $term = $context['data']['taxonomy_term'];
      }
    }
    elseif ($context['type'] == 'entity' && $context['data']['entity_type'] == 'taxonomy_term') {
      $term = $context['data']['entity'];
    }
    if ($term) {
      $replacements[$token] = $sanitize ? filter_xss($term->machine_name) : $term->machine_name;
    }
  }
}