Issue #2470952 by D Szkiba: Path deletion should be removed in path module after content translation removal.

8.0.x
Alex Pott 2015-04-17 10:22:03 +02:00
parent f347360a1e
commit 612581d7f0
3 changed files with 15 additions and 8 deletions

View File

@ -77,14 +77,6 @@ class ContentTranslationDeleteForm extends ConfirmFormBase {
$this->entity->removeTranslation($this->language->getId());
$this->entity->save();
// Remove any existing path alias for the removed translation.
// @todo This should be taken care of by the Path module.
if (\Drupal::moduleHandler()->moduleExists('path')) {
$path = $this->entity->urlInfo()->getInternalPath();
$conditions = array('source' => $path, 'langcode' => $this->language->getId());
\Drupal::service('path.alias_storage')->delete($conditions);
}
$form_state->setRedirectUrl($this->getCancelUrl());
}

View File

@ -5,6 +5,7 @@
* Enables users to rename URLs.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\BaseFieldDefinition;
@ -77,3 +78,12 @@ function path_entity_base_field_info(EntityTypeInterface $entity_type) {
return $fields;
}
}
/**
* Implements hook_entity_translation_delete().
*/
function path_entity_translation_delete(EntityInterface $translation) {
$path = $translation->urlInfo()->getInternalPath();
$conditions = array('source' => $path, 'langcode' => $translation->language()->getId());
\Drupal::service('path.alias_storage')->delete($conditions);
}

View File

@ -186,5 +186,10 @@ class PathLanguageTest extends PathTestBase {
// Second call should return the same alias.
$french_node_alias = $this->container->get('path.alias_manager')->getAliasByPath('node/' . $english_node_french_translation->id(), 'fr');
$this->assertEqual($french_node_alias, $french_alias, 'Alias is the same.');
// Confirm that the alias is removed if the translation is deleted.
$english_node->removeTranslation('fr');
$english_node->save();
$this->assertFalse($this->container->get('path.alias_storage')->aliasExists($french_alias, 'fr'), 'Alias for French translation is removed when translation is deleted.');
}
}