When attempting to render a Taxonomy Term while still new (i.e. when setting a Layout Builder default Layout), you will receive:

Drupal\Core\Entity\EntityMalformedException: The "taxonomy_term" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\EntityBase->toUrl() (line 191 of /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php)

This is due to the Taxonomy module and RDF module using `$term->toUrl()` without checking if the term is new.

Steps to reproduce:

  • Enable Layout Builder
  • On Article default display (/admin/structure/types/manage/article/display) set tags to widget "Rendered Entity"
  • Enable Layout Builder on Default display
  • Click "Manage Layout"
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

b_sharpe created an issue. See original summary.

b_sharpe’s picture

Status: Active » Needs review
FileSize
1.34 KB
tatarbj’s picture

Status: Needs review » Needs work

Even the patch seems quite straight forward, I've tried to reproduce the issue on a new 8.7.x drupal standard site, enabling layout_builder, but whenever I create a new taxonomy term, using the shipped Tags one, I always get the same page where it's indicated the new term is created and available under its link - when I click it, I have no issues (layout_builder is in use for this taxonomy).

Could you give a bit more step-by-step reproduction to the issue itself?

Bests,
Balazs.

b_sharpe’s picture

Status: Needs work » Needs review

Steps to reproduce:

  • On Artical default display (/admin/structure/types/manage/article/display) set tags to widget "Rendered Entity"
  • Enable "Full Content" display mode
  • Enable Layout Builder on Full Content
  • Click "Manage Layout"

This is due to Layout Builder attempting to generate "preview" data, which creates a New Taxonomy Term entity to be rendered that triggers the code fixed in the patch.

Jérôme Dehorter’s picture

Hi,

Patch works for me to solve "Rendered entity" choice for taxonomy term with custom fields.
I am on Drupal 8.7.4.

jonraedeke’s picture

This patch works for me as well. I was using Layout Builder for a term page and attempting to add the "Entity view (Taxonomy term)" block. This threw an AJAX error similar to the issue description. After saving the Layout Builder settings, that LB edit page threw a similar fatal error.

sker101’s picture

The patch works for me. I'm using another view in one of my view as "entity view" in the layout builder and it's throwing the error since the entity in the entity view is not an existing entity.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

b_sharpe’s picture

Reroll for 8.8, trying to look into how to build a test around this, but interestingly enough there doesn't seem to be any test coverage around unsaved nodes or terms that i can find, so for now just leaving the patch for those who need.

b_sharpe’s picture

OK I lied, here is a test to confirm issue and combined patch to confirm fixed.

The last submitted patch, 10: malformedentityexception-3059387-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

b_sharpe’s picture

The last submitted patch, 12: malformedentityexception-3059387-test-only-2.patch, failed testing. View results

b_sharpe’s picture

Version: 8.8.x-dev » 8.9.x-dev
b_sharpe’s picture

Issue summary: View changes
AaronChristian’s picture

FileSize
372.31 KB
144.42 KB

Looks good to me. Tested with 8.8.1 & 8.9.x-dev.

Marking as RTBC, thanks for fixing this annoying core bug!

Before:

3059387-before

After:

3059387-after

AaronChristian’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: malformedentityexception-3059387-combined-2.patch, failed testing. View results

b_sharpe’s picture

Priority: Normal » Major
Status: Needs work » Needs review

Failed test seems unrelated, triggering again, also bumping to major given this takes minimal steps to reproduce and is a FATAL from core.

b_sharpe’s picture

Status: Needs review » Reviewed & tested by the community

As expected test fail unrelated, back to RTBC

  • webchick committed a35bbaf on 9.0.x
    Issue #3059387 by b_sharpe, AaronChristian: Taxonomy Terms cannot be...

  • webchick committed a03e7af on 8.9.x
    Issue #3059387 by b_sharpe, AaronChristian: Taxonomy Terms cannot be...

  • webchick committed 37d0450 on 8.8.x
    Issue #3059387 by b_sharpe, AaronChristian: Taxonomy Terms cannot be...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nice catch! Thanks for the fix, and for the helpful screenshots showing the fix in action!

Committed and pushed to 9.0.x, 8.9.x, and 8.8.x. Thanks!

Status: Fixed » Closed (fixed)

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