Commit 612581d7 authored by alexpott's avatar alexpott

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

Issue #2470952 by D Szkiba: Path deletion should be removed in path module after content translation removal.
parent f347360a
......@@ -77,14 +77,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$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());
}
......
......@@ -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);
}
......@@ -186,5 +186,10 @@ function testAliasTranslation() {
// 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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment