diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 9b4d2f7cb8..a4288701e3 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -184,15 +184,15 @@ public function toUrl($rel = 'canonical', array $options = []) { $link_templates = $this->linkTemplates(); if ($rel === 'revision' && $this instanceof RevisionableInterface) { - // Unsaved revisions cannot be linked to. - if ($this->isNewRevision()) { - throw new EntityMalformedException(sprintf('The "%s" entity cannot have a revision URI as it is an unsaved revision yet.', $this->getEntityTypeId())); - } // Links pointing to the current revision point to the actual entity. So // instead of using the 'revision' link, use the 'canonical' link. - elseif ($this->isDefaultRevision()) { + if ($this->isDefaultRevision()) { $rel = 'canonical'; } + elseif ($this->isNewRevision()) { + // Unsaved revisions cannot be linked to. + throw new EntityMalformedException(sprintf('The "%s" entity cannot have a revision URI as it is an unsaved revision yet.', $this->getEntityTypeId())); + } } if (isset($link_templates[$rel])) {