You are here

function path_taxonomy_term_update in Drupal 7

Implements hook_taxonomy_term_update().

File

modules/path/path.module, line 286
Enables users to rename URLs.

Code

function path_taxonomy_term_update($term) {
  if (isset($term->path)) {
    $path = $term->path;
    $path['alias'] = trim($path['alias']);

    // Delete old alias if user erased it.
    if (!empty($path['pid']) && empty($path['alias'])) {
      path_delete($path['pid']);
    }

    // Only save a non-empty alias.
    if (!empty($path['alias'])) {

      // Ensure fields for programmatic executions.
      $path['source'] = 'taxonomy/term/' . $term->tid;

      // Core does not provide a way to store the term language but contrib
      // modules can do it so we need to take this into account.
      $langcode = entity_language('taxonomy_term', $term);
      $path['language'] = !empty($langcode) ? $langcode : LANGUAGE_NONE;
      path_save($path);
    }
  }
}