Problem/Motivation

When editing a default layout for a content type, blocks are shown for every paragraph field on the site, not just the ones on the content type being configured. If someone tries to add a block for a paragraph field that is not on the content type, the operation fails without a message BUT after saving the layout it becomes corrupted.

Steps to reproduce

  1. Create new paragraph fields on a content type. Using "Article" and "Basic Page" as examples, create "article_paragraph" on the Article content type.
  2. Enable Layout Builder for Basic Page and click "Manage layout".
  3. Add a block and choose one of the paragraph blocks for the article_paragraph field. The block shouldn't actually be placed in the UI. Save the layout.
  4. Click "Manage layout" again. This time you will get "The website encountered an unexpected error. Please try again later."
  5. Check the logs. There is a PHP error: InvalidArgumentException: Field field_article_paragraph is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 587 of /var/www/html.original/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Proposed resolution

Ideally, paragraph blocks for fields from other content types wouldn't be shown when editing a layout. Additionally, it would be nice if somehow someone did manage to attempt to add an invalid field, it wouldn't break the layout for the content type.

Comments

jhaskins created an issue. See original summary.

jhaskins’s picture

Looking at how FieldBlockDeriver in core restricts fields by bundle, it appears that it's just a matter of adding an EntityContextDefinition witha bundle constraint. Here's a patch that tweaks the context definitions in the deriver to match what core is doing. This is preventing blocks for paragraph fields that aren't on the bundle from being shown.

jhaskins’s picture

Status: Active » Needs review
mallezie’s picture

Rerolled patch

basvredeling’s picture

Status: Needs review » Closed (duplicate)

This will not be fixed in the 2.x branch. Closed in favour of #3189092: Attempting to add a paragraph from another content type breaks layout builder.

basvredeling’s picture

Version: 8.x-2.1-beta5 » 3.x-dev
Assigned: Unassigned » basvredeling
Status: Closed (duplicate) » Needs review

Closed the wrong issue. This needs to be open and reviewed. Will do so now.

  • basvredeling committed 7cac7aa on 3.x
    Issue #3170138 by jhaskins, mallezie, basvredeling: Attempting to add a...
basvredeling’s picture

Status: Needs review » Fixed

Merged, thanks for contributing @jhaskins @mallezie

basvredeling’s picture

Assigned: basvredeling » Unassigned
Status: Fixed » Closed (fixed)