Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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"
Comment | File | Size | Author |
---|---|---|---|
#16 | 3059387-after.png | 144.42 KB | AaronChristian |
#16 | 3059387-before.png | 372.31 KB | AaronChristian |
#12 | interdiff.txt | 171 bytes | b_sharpe |
#12 | malformedentityexception-3059387-combined-2.patch | 2.6 KB | b_sharpe |
#12 | malformedentityexception-3059387-test-only-2.patch | 1.26 KB | b_sharpe |
Comments
Comment #2
b_sharpe CreditAttribution: b_sharpe at ImageX commentedComment #3
tatarbjEven 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.
Comment #4
b_sharpe CreditAttribution: b_sharpe at ImageX commentedSteps to reproduce:
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.
Comment #5
Jérôme DehorterHi,
Patch works for me to solve "Rendered entity" choice for taxonomy term with custom fields.
I am on Drupal 8.7.4.
Comment #6
jonraedeke CreditAttribution: jonraedeke commentedThis 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.
Comment #7
sker101 CreditAttribution: sker101 as a volunteer commentedThe 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.
Comment #9
b_sharpe CreditAttribution: b_sharpe at ImageX commentedReroll 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.
Comment #10
b_sharpe CreditAttribution: b_sharpe at ImageX commentedOK I lied, here is a test to confirm issue and combined patch to confirm fixed.
Comment #12
b_sharpe CreditAttribution: b_sharpe at ImageX commentedNo functional changes, just fixing missing method visibility.
Comment #14
b_sharpe CreditAttribution: b_sharpe at ImageX commentedComment #15
b_sharpe CreditAttribution: b_sharpe at ImageX commentedComment #16
AaronChristian CreditAttribution: AaronChristian at ImageX commentedLooks good to me. Tested with 8.8.1 & 8.9.x-dev.
Marking as RTBC, thanks for fixing this annoying core bug!
Before:
After:
Comment #17
AaronChristian CreditAttribution: AaronChristian at ImageX commentedComment #19
b_sharpe CreditAttribution: b_sharpe at ImageX commentedFailed test seems unrelated, triggering again, also bumping to major given this takes minimal steps to reproduce and is a FATAL from core.
Comment #20
b_sharpe CreditAttribution: b_sharpe at ImageX commentedAs expected test fail unrelated, back to RTBC
Comment #24
webchickNice 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!