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

  1. Enable the patternkit and patternkit_example modules
  2. Create a node type with layout builder enabled
  3. Edit the default layout for the node type
  4. Attempt to add a patternkit block into one of the sections
  5. (X) Observe no response when clicking the pattern name
  6. 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

Command icon 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

slucero created an issue. See original summary.

slucero’s picture

Status: Active » Needs review
Parent issue: » #3296167: Beta 5 Release Plan

I'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.

slucero credited staceroni.

slucero’s picture

  • slucero committed a0937e9 on 9.1.x
    Issue #3307383 by slucero, staceroni: Block Form Fails on Content Type...
slucero’s picture

Status: Needs review » Fixed

Merged for inclusion in the Beta 5 release!

Status: Fixed » Closed (fixed)

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