Creating a new issue clone as the original issue got closed as fixed but there are more people with the same issue still.
#3110455: Metatags depending on URL cause errors for unsaved entities after updating to Drupal 8.8.0

Original IS:

Hi,

I recently updated to Drupal Core 8.8.0 and then 8.8.1 and I am now getting the following error on various pages like `/node/add/page`: 1 error has been found: Title

In the Drupal Log report I see:

Location: /node/add/page?_wrapper_format=drupal_ajax&ajax_form=1
Referrer: /node/add/page
Message: Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\EntityBase->toUrl() (line 192 of /app/web/core/lib/Drupal/Core/Entity/EntityBase.php).
Severity: Error

Comments

BramDriesen created an issue. See original summary.

bramdriesen’s picture

Version: 8.x-2.0-alpha10 » 8.x-2.x-dev
StatusFileSize
new917 bytes
new1.14 KB

Uploading patches.

#21 by: bojan_dev
#22 by: StanleyFernandes

We are using #22 for quite some time in prod now.

bramdriesen’s picture

Status: Active » Needs review
drumanuel’s picture

Got this issue on Drupal 10.3. Patch does not apply.

drumanuel’s picture

StatusFileSize
new1.14 KB

Created a patch for 2.0.0-alpha10

carma03’s picture

Confirming patch yoast_seo-3110455-22.patch works for me on D10.2.6, PHP 8.1.29, Apache 2.4.41 and MySQL5.7.

Thanks @BramDriesen and @Drumanuel

bramdriesen’s picture

Status: Needs review » Reviewed & tested by the community

Let's go for RTBC then!

  • kingdutch committed b59fac39 on 8.x-2.x
    Issue #3418620 by bramdriesen, drumanuel, carma03: Metatags depending on...
kingdutch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the contribution! I've gone with the smaller fix:

diff --git a/src/EntityAnalyser.php b/src/EntityAnalyser.php
index 0734233..e6555cf 100644
--- a/src/EntityAnalyser.php
+++ b/src/EntityAnalyser.php
@@ -213,7 +213,7 @@ class EntityAnalyser {
     foreach ($metatags as $tag => $value) {
       $metatags[$tag] = str_replace('[current-page:title]', $entity->label() ?? '', $value);
       // URL metatags cause issues for new nodes as they don't have a URL yet.
-      if ($entity->isNew() && (substr($tag, -4) === '_url')) {
+      if ($entity->isNew() && preg_match('/[.\-_:]url/', $value)) {
         $metatags[$tag] = '';
       }
     }

The other patch also changed the logic of the title by moving $entity->isNew() outside of the loop altogether, which seemed to do something differently than what was needed for the bug report.

If this issue persists, please ping me on Slack and we can replace it by one of the other patches.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.