function path_node_update

Implements hook_node_update().

File

drupal/core/modules/path/path.module, line 203
Enables users to rename URLs.

Code

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']);
    }
  }
}