Commit 075da62c authored by Berdir's avatar Berdir Committed by Berdir
Browse files

Issue #2847672 by Berdir: Only generate aliases for the default revision

parent ee42d40c
......@@ -6,6 +6,7 @@ use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\BubbleableMetadata;
......@@ -307,6 +308,11 @@ class PathautoGenerator implements PathautoGeneratorInterface {
return NULL;
}
// Only act if this is the default revision.
if ($entity instanceof RevisionableInterface && !$entity->isDefaultRevision()) {
return NULL;
}
$options += array('language' => $entity->language()->getId());
$type = $entity->getEntityTypeId();
......
......@@ -532,6 +532,21 @@ class PathautoKernelTest extends KernelTestBase {
}
/**
* Tests that aliases are only generated for default revisions.
*/
public function testDefaultRevision() {
$node1 = $this->drupalCreateNode(['title' => 'Default revision', 'type' => 'page']);
$this->assertEntityAlias($node1, '/content/default-revision');
$node1->setNewRevision(TRUE);
$node1->isDefaultRevision(FALSE);
$node1->setTitle('New non-default-revision');
$node1->save();
$this->assertEntityAlias($node1, '/content/default-revision');
}
/**
* Creates a node programmatically.
*
......
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