0

In Drupal 7, a path alias can be deleted with code similar to the following one.

path_delete(array('source' => "problem/{$problem->nid}/{$problem_src->nid}"));

How can I delete path aliases in Drupal 9?

Thanks..

1 Answer 1

4

Delete path alias: Drupal(8/9/10)

$path_alias_manager = \Drupal::entityTypeManager()->getStorage('path_alias');
// Load path alias by path
$alias_objects = $path_alias_manager->loadByProperties([
  'path' => '/node/' . $nid
]);
foreach ($alias_objects as $alias_object) {
  // Delete the path alias
  $alias_object->delete();
}  

Note: Drupal(8/9/10) "path" field column maintained instead of "source" column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.