- ๐ฎ๐ณIndia StanleyFernandes Goa
consider this issue also to fix the error reported :
https://www.drupal.org/project/yoast_seo/issues/3110455 ๐ Metatags depending on URL cause errors for unsaved entities after updating to Drupal 8.8.0 Fixed - ๐บ๐ธUnited States gcb
@Berdir the core module layout_builder regularly renders content with sample entities in its UX. These sample entities do not have IDs. As a result, if you use a URI token anywhere on a default layout, the layout builder screen is crashed by this issue.
The function
\Drupal\Core\Entity\EntityBase::toUrl()
begins with a check for a Null entity ID, and throws an exception if there's no ID. Passing an entity to this function without checking for an ID first is asking for whitescreens -- new, unsaved entities are valid for rendering according to Drupal standards. See the discussion in https://www.drupal.org/project/drupal/issues/3069001 ๐ Layout builder's use of sample data can cause exceptions during rendering of default entity view displays Needs work about having contrib modules sensibly handling "preview" content. - Status changed to Needs review
12 months ago 7:58pm 27 November 2023 - last update
12 months ago 77 pass - ๐บ๐ธUnited States tim.plunkett Philadelphia
+++ b/token.tokens.inc @@ -569,7 +569,7 @@ function token_tokens($type, array $tokens, array $data, array $options, Bubblea + if (($url_tokens = \Drupal::token()->findWithPrefix($tokens, 'url')) && $node->id() !== NULL) {
Could also use
!empty($node->in_preview)
. That pre-dates LB (think original node preview) but is also set when LB generates the sample entity. - ๐ฎ๐ณIndia prashant.c Dharamshala
Prashant.c โ made their first commit to this issueโs fork.
- last update
12 months ago 77 pass - Status changed to Needs work
12 months ago 8:14pm 12 December 2023 - ๐จ๐ญSwitzerland berdir Switzerland
I don't think in preview is the right thing to check here. you can also preview an existing, already saved node with an ID.
We have an existing case that checks for isNew(), for the generic entity:url token, no strong preference betweenn isNew() and id(). I suppose id() could in edge cases be more reliable.
Remaining tasks:
* As mentioned earlier, node_tokens() in core has the same issue, aka the :url and :edit-url tokens, and a core issue should be opened to improve this.
* Either add checks for other toUrl() calls in token replacements in this module or create a follow-up.
* As usual, tests will make it more likely that this gets committed. Look for exsting tests for those tokens, copy paste with a new node, ensure it doesn't throw an error (assert for not replacing the token).