diff --git a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php index 495253d158..ea95c9842e 100644 --- a/core/modules/path/src/Plugin/Field/FieldType/PathItem.php +++ b/core/modules/path/src/Plugin/Field/FieldType/PathItem.php @@ -63,17 +63,15 @@ public function postSave($update) { } } - if (!$update) { - if ($source) { - if ($path = \Drupal::service('path.alias_storage')->save('/' . $source, $this->alias, $this->getLangcode())) { + if ($source && (!$update || $source != $this->source)) { + if ($path = \Drupal::service('path.alias_storage')->save('/' . $source, $this->alias, $this->getLangcode())) { $this->pid = $path['pid']; - } } } else { // Delete old alias if user erased it. - if ($this->pid && !$this->alias) { - \Drupal::service('path.alias_storage')->delete(['pid' => $this->pid]); + if (!$this->alias) { + \Drupal::service('path.alias_storage')->delete(['source' => $source]); } // Only save a non-empty alias. elseif ($source) { diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index b31af4694b..a6805c5b91 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -28,7 +28,12 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $entity = $items->getEntity(); $path = []; if (!$entity->isNew()) { - $conditions = ['source' => '/' . $entity->urlInfo()->getInternalPath()]; + if ($entity->getEntityType()->isRevisionable() && !$entity->isDefaultRevision()) { + $conditions = ['source' => '/' . $entity->toUrl('revision')->getInternalPath()]; + } + else { + $conditions = ['source' => '/' . $entity->toUrl()->getInternalPath()]; + } if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) { $conditions['langcode'] = $items->getLangcode(); } diff --git a/core/modules/path/tests/src/Functional/PathContentModerationTest.php b/core/modules/path/tests/src/Functional/PathContentModerationTest.php index e69de29bb2..7b2c66057c 100644 --- a/core/modules/path/tests/src/Functional/PathContentModerationTest.php +++ b/core/modules/path/tests/src/Functional/PathContentModerationTest.php @@ -0,0 +1,105 @@ + 'moderated', 'type' => 'moderated']); + $node_type->save(); + + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated'); + $workflow->save(); + + $this->drupalLogin($this->rootUser); + } + + public function testNodePathAlias() { + $this->drupalPostForm('node/add/moderated', [ + 'title[0][value]' => 'moderated content', + 'path[0][alias]' => '/moderated-content', + ], t('Save and Publish')); + $node = $this->getNodeByTitle('moderated content'); + + $this->drupalGet('/moderated-content'); + $this->assertSession()->pageTextContains('moderated content'); + + $this->drupalPostForm('node/' . $node->id() . '/edit', [ + 'title[0][value]' => 'forward revision', + 'path[0][alias]' => '/forward-revision', + ], t('Save and Create New Draft')); + + $this->drupalGet('/forward-revision'); + $this->assertSession()->pageTextNotContains('moderated content'); + $this->assertSession()->pageTextContains('forward revision'); + $this->drupalGet('/moderated-content'); + $this->assertSession()->pageTextNotContains('forward revision'); + $this->assertSession()->pageTextContains('moderated content'); + + $this->drupalPostForm('node/' . $node->id() . '/edit', [ + 'title[0][value]' => 'revision three', + 'path[0][alias]' => '/revision-three', + ], t('Save and Create New Draft')); + + $this->drupalGet('/revision-three'); + $this->assertSession()->pageTextNotContains('moderated content'); + $this->assertSession()->pageTextNotContains('forward revision'); + $this->assertSession()->pageTextContains('revision three'); + $this->drupalGet('/forward-revision'); + $this->assertSession()->pageTextNotContains('moderated content'); + $this->assertSession()->pageTextContains('forward revision'); + $this->assertSession()->pageTextNotContains('revision three'); + $this->drupalGet('/moderated-content'); + $this->assertSession()->pageTextNotContains('forward revision'); + $this->assertSession()->pageTextContains('moderated content'); + $this->assertSession()->pageTextNotContains('revision three'); + + $this->drupalPostForm('node/' . $node->id() . '/edit', [ + 'title[0][value]' => 'revision four', + 'path[0][alias]' => '', + ], t('Save and Create New Draft')); + + $this->drupalGet('/node/1/revisions/4/view'); + $this->assertSession()->pageTextNotContains('moderated content'); + $this->assertSession()->pageTextNotContains('forward revision'); + $this->assertSession()->pageTextNotContains('revision three'); + $this->assertSession()->pageTextContains('revision four'); + $this->drupalGet('/revision-three'); + $this->assertSession()->pageTextNotContains('moderated content'); + $this->assertSession()->pageTextNotContains('forward revision'); + $this->assertSession()->pageTextContains('revision three'); + $this->assertSession()->pageTextNotContains('revision four'); + $this->drupalGet('/forward-revision'); + $this->assertSession()->pageTextNotContains('moderated content'); + $this->assertSession()->pageTextContains('forward revision'); + $this->assertSession()->pageTextNotContains('revision three'); + $this->assertSession()->pageTextNotContains('revision four'); + $this->drupalGet('/moderated-content'); + $this->assertSession()->pageTextNotContains('forward revision'); + $this->assertSession()->pageTextContains('moderated content'); + $this->assertSession()->pageTextNotContains('revision three'); + $this->assertSession()->pageTextNotContains('revision four'); + } +} \ No newline at end of file