Implements hook_taxonomy_term_insert().
function path_taxonomy_term_insert(Term $term) {
if (isset($term->path)) {
$path = $term->path;
$path['alias'] = trim($path['alias']);
// Only save a non-empty alias.
if (!empty($path['alias'])) {
// 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']);
}
}
}