Implements hook_node_update().
function path_node_update(EntityInterface $node) {
if (isset($node->path)) {
$path = $node->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'])) {
// Ensure fields for programmatic executions.
$source = 'node/' . $node->nid;
$langcode = isset($node->langcode) ? $node->langcode : Language::LANGCODE_NOT_SPECIFIED;
drupal_container()
->get('path.crud')
->save($source, $alias, $langcode, $path['pid']);
}
}
}