- Issue created by @J-Lee
If a node has a hreflang tag configured and a new node (never saved) is to be displayed in the preview, an error is triggered:
Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID at Drupal\Core\Entity\EntityBase->toUrl() (Line 161 in /core/lib/Drupal/Core/Entity/EntityBase.php).
The error source comes from /metatag/metatag_hreflang/metatag_hreflang.tokens.inc
(Line 124): Drupal\Core\Entity\EntityBase->toUrl('canonical')
1. Activate the hreflang tags in the metatags settings for nodes.
2. Create a new node and click on the Preview button.
In several places in metatag_hreflang.tokens.inc there are calls to Entity::toUrl()
e.g. $entity->toUrl('canonical')
.
Since the new entity has no ID, Entity::toUrl() throws the EntityMalformedException.
One possible solution is to surround the toUrl() calls with a try-catch and return an empty value in the event of an error.
Active
2.0
Code