You are here

function redirect_entity_delete in Redirect 8

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_entity_delete()
  2. 7 redirect.module \redirect_entity_delete()

Implements hook_entity_delete().

Will delete redirects based on the entity URL.

File

./redirect.module, line 73
The redirect module.

Code

function redirect_entity_delete(EntityInterface $entity) {
  try {
    if ($entity
      ->getEntityType()
      ->hasLinkTemplate('canonical') && $entity
      ->toUrl('canonical')
      ->isRouted()) {
      redirect_delete_by_path('internal:/' . $entity
        ->toUrl('canonical')
        ->getInternalPath());
      redirect_delete_by_path('entity:' . $entity
        ->getEntityTypeId() . '/' . $entity
        ->id());
    }
  } catch (RouteNotFoundException $e) {

    // This can happen if a module incorrectly defines a link template, ignore
    // such errors.
  }
}