Implements hook_taxonomy_term_update().
function path_taxonomy_term_update(Term $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'])) {
drupal_container()
->get('path.crud')
->delete(array(
'pid' => $path['pid'],
));
}
// Only save a non-empty alias.
if (!empty($path['alias'])) {
$pid = !empty($path['pid']) ? $path['pid'] : NULL;
// Ensure fields for programmatic executions.
$path['source'] = 'taxonomy/term/' . $term->tid;
$path['langcode'] = LANGUAGE_NOT_SPECIFIED;
drupal_container()
->get('path.crud')
->save($path['source'], $path['alias'], $path['langcode'], $pid);
}
}
}