Problem/Motivation
When attempting to place a patternkit block on a default layout for a Node, the form fails to load and an AJAX error is returned with no visible feedback. In the logs, the following error message is recorded:
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 161 of /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php).
Steps to reproduce
- Enable the patternkit and patternkit_example modules
- Create a node type with layout builder enabled
- Edit the default layout for the node type
- Attempt to add a patternkit block into one of the sections
- (X) Observe no response when clicking the pattern name
- View the site logs and observe the error message described above
Proposed resolution
After some digging, this appears to be caused by the token listing on the edit form which attempts to render the token value to display as an example. When the [node:url] and [node:edit-url] tokens are rendered, the logged exception is thrown because the Node being rendered doesn't have an ID yet.
To address this, I suggest wrapping the rendering of the token for this example value in a try/catch and excluding the example value if it fails.
Remaining tasks
- Review and testing
User interface changes
The block form token listing excludes examples for tokens that cannot be rendered for the current context.
API changes
None
Data model changes
None
Issue fork patternkit-3307383
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
sluceroI've uploaded an MR addressing this issue following the proposed solution. It also includes a browser test completing placement and rendering of a block on a default layout which fails at the edit form step without this fix in place.
Comment #5
sluceroComment #7
sluceroMerged for inclusion in the Beta 5 release!