diff --git a/web/modules/custom/leshed_helpers/leshed_helpers.module b/web/modules/custom/leshed_helpers/leshed_helpers.module index 791667b..0267926 100644 --- a/web/modules/custom/leshed_helpers/leshed_helpers.module +++ b/web/modules/custom/leshed_helpers/leshed_helpers.module @@ -30,6 +30,24 @@ function leshed_helpers_taxonomy_term_update(EntityInterface $entity) { leshed_helpers_ensure_term_alias($entity); } +/** + * Supprime l'alias d'URL quand un terme d'un vocabulaire géré est supprimé. + */ +function leshed_helpers_taxonomy_term_delete(EntityInterface $entity) { + if (!($entity instanceof TermInterface)) { + return; + } + + $vid = $entity->bundle(); + if (!isset(LESHED_HELPERS_VOCABULARIES[$vid])) { + return; + } + + $internal_path = '/' . LESHED_HELPERS_VOCABULARIES[$vid] . '/' . $entity->id(); + $storage = \Drupal::entityTypeManager()->getStorage('path_alias'); + $storage->delete($storage->loadByProperties(['path' => $internal_path])); +} + function leshed_helpers_ensure_term_alias(EntityInterface $entity) { if (!($entity instanceof TermInterface)) { return;