Metatags depending on URL cause errors for unsaved entities after updating to Drupal 10.1.4

Created on 1 February 2024, 12 months ago

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

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

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium BramDriesen Belgium 🇧🇪

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @BramDriesen
  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    Uploading patches.

    #21 by: bojan_dev
    #22 by: StanleyFernandes

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

  • Status changed to Needs review 12 months ago
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 12 months ago
    Waiting for branch to pass
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 12 months ago
    Waiting for branch to pass
  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪
  • 🇳🇱Netherlands Drumanuel

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

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 7 months ago
    Waiting for branch to pass
  • 🇳🇱Netherlands Drumanuel

    Created a patch for 2.0.0-alpha10

  • 🇨🇴Colombia carma03

    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

  • Status changed to RTBC 6 months ago
  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    Let's go for RTBC then!

    • kingdutch committed b59fac39 on 8.x-2.x
      Issue #3418620 by bramdriesen, drumanuel, carma03: Metatags depending on...
  • 🇳🇱Netherlands kingdutch

    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.

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

Production build 0.71.5 2024