You are here

function pathauto_taxonomy_term_update_alias in Pathauto 7

Same name and namespace in other branches
  1. 6.2 pathauto.module \pathauto_taxonomy_term_update_alias()

Update the URL aliases for an individual taxonomy term.

Parameters

$term: A taxonomy term object.

$op: Operation being performed on the term ('insert', 'update' or 'bulkupdate').

$options: An optional array of additional options.

4 calls to pathauto_taxonomy_term_update_alias()
pathauto_taxonomy_term_insert in ./pathauto.module
Implements hook_taxonomy_term_insert().
pathauto_taxonomy_term_update in ./pathauto.module
Implements hook_taxonomy_term_update().
pathauto_taxonomy_term_update_action in ./pathauto.module
Update action wrapper for pathauto_taxonomy_term_update_alias().
pathauto_taxonomy_term_update_alias_multiple in ./pathauto.module
Update the URL aliases for multiple taxonomy terms.

File

./pathauto.module, line 878
Main file for the Pathauto module, which automatically generates aliases for content.

Code

function pathauto_taxonomy_term_update_alias(stdClass $term, $op, array $options = array()) {

  // Skip processing if the user has disabled pathauto for the term.
  if (isset($term->path['pathauto']) && empty($term->path['pathauto']) && empty($options['force'])) {
    return FALSE;
  }
  $module = 'taxonomy_term';
  if ($term->vid == variable_get('forum_nav_vocabulary', '')) {
    if (module_exists('forum')) {
      $module = 'forum';
    }
    else {
      return FALSE;
    }
  }

  // Check that the term has its bundle, which is the vocabulary's machine name.
  if (!isset($term->vocabulary_machine_name)) {
    $vocabulary = taxonomy_vocabulary_load($term->vid);
    $term->vocabulary_machine_name = $vocabulary->machine_name;
  }
  $options += array(
    'alias children' => FALSE,
    'language' => pathauto_entity_language('taxonomy_term', $term),
  );

  // Skip processing if the term has no pattern.
  if (!pathauto_pattern_load_by_entity($module, $term->vocabulary_machine_name)) {
    return FALSE;
  }
  module_load_include('inc', 'pathauto');
  $uri = entity_uri('taxonomy_term', $term);
  $result = pathauto_create_alias($module, $op, $uri['path'], array(
    'term' => $term,
  ), $term->vocabulary_machine_name, $options['language']);
  if (!empty($options['alias children'])) {

    // For all children generate new aliases.
    unset($options['language']);
    foreach (taxonomy_get_children($term->tid, $term->vid) as $subterm) {
      pathauto_taxonomy_term_update_alias($subterm, $op, $options);
    }
  }
  return $result;
}