diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 95e85e2..11c3ad1 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -176,6 +176,12 @@ public function urlInfo($rel = 'canonical', array $options = []) { * {@inheritdoc} */ public function toUrl($rel = 'canonical', array $options = []) { + // If attempting to preview a new and unsaved entity, it will not have an ID. + // In order for the preview to display properly, create a link to the front page. + if ($this->isNew() && property_exists($this, 'in_preview') && $this->in_preview === TRUE) { + return Url::fromRoute(''); + } + if ($this->id() === NULL) { throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does not have an ID', $this->getEntityTypeId())); }