Implements hook_taxonomy_term_update().
function path_taxonomy_term_update(Term $term) {
if (isset($term->path)) {
$term->path->alias = trim($term->path->alias);
// Delete old alias if user erased it.
if (!empty($term->path->pid) && empty($term->path->alias)) {
Drupal::service('path.crud')
->delete(array(
'pid' => $term->path->pid,
));
}
// Only save a non-empty alias.
if ($term->path->alias) {
$pid = !empty($term->path->pid) ? $term->path->pid : NULL;
// Ensure fields for programmatic executions.
$source = 'taxonomy/term/' . $term
->id();
$langcode = Language::LANGCODE_NOT_SPECIFIED;
Drupal::service('path.crud')
->save($source, $term->path->alias, $langcode, $pid);
}
}
}