diff --cc core/modules/path/path.module index 38cb57beee,328c434c33..0000000000 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@@ -5,7 -5,7 +5,8 @@@ * Enables users to rename URLs. */ +use Drupal\Core\Entity\ContentEntityInterface; + use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; @@@ -79,15 -79,15 +80,30 @@@ function path_entity_base_field_info(En } /** + * Implements hook_entity_translation_create(). + */ +function path_entity_translation_create(ContentEntityInterface $translation) { + foreach ($translation->getFieldDefinitions() as $field_name => $field_definition) { + if ($field_definition->getType() === 'path' && $translation->get($field_name)->pid) { + // If there are values and a path ID, update the langcode and unset the + // path ID to save this as a new alias. - $translation->get($field_name)->langcode = $translation->language()->getId(); ++ $translation->get($field_name)->langcode = $translation->language() ++ ->getId(); + $translation->get($field_name)->pid = NULL; + } + } +} ++ ++/** + * Implements hook_entity_revision_delete(). + */ + function path_entity_revision_delete(EntityInterface $entity) { + $entity_type_id = $entity->getEntityTypeId(); + $source = str_replace('{' . $entity_type_id . '}', $entity->id(), $entity->getEntityType()->getLinkTemplate('revision')); + $source = str_replace('{' . $entity_type_id . '_revision}', '%', $source); + $revisionable_conditions = [ + 'source' => $source, + 'langcode' => $entity->language()->getId(), + ]; + \Drupal::service('path.alias_storage')->delete($revisionable_conditions); + } diff --cc core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index 13ab1f1076,cd14910317..0000000000 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index d66f75df54..75c82dbe8d 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -174,12 +174,19 @@ protected function ensureLoaded() { if (!$this->isLoaded) { $entity = $this->getEntity(); if (!$entity->isNew()) { + if ($entity->getEntityType()->isRevisionable() && !$entity->isDefaultRevision()) { + $conditions = ['source' => [ + '/' . $entity->toUrl('revision')->getInternalPath(), + '/' . $entity->toUrl()->getInternalPath(), + ]]; + } + else { + $conditions = ['source' => '/' . $entity->toUrl()->getInternalPath()]; + } + $conditions['langcode'] = $this->getLangcode(); // @todo Support loading languge neutral aliases in // https://www.drupal.org/node/2511968. - $alias = \Drupal::service('path.alias_storage')->load([ - 'source' => '/' . $entity->toUrl()->getInternalPath(), - 'langcode' => $this->getLangcode(), - ]); + $alias = \Drupal::service('path.alias_storage')->load($conditions); if ($alias) { $this->setValue($alias); }