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
- Create new paragraph fields on a content type. Using "Article" and "Basic Page" as examples, create "article_paragraph" on the Article content type.
- Enable Layout Builder for Basic Page and click "Manage layout".
- 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.
- Click "Manage layout" again. This time you will get "The website encountered an unexpected error. Please try again later."
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3170138-only-show-paragraphs-for-current-bundle-3.x.patch | 1 KB | mallezie |
| #2 | 3170138-only-show-paragraphs-for-current-bundle.patch | 1.56 KB | jhaskins |
Comments
Comment #2
jhaskins commentedLooking 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.
Comment #3
jhaskins commentedComment #4
mallezieRerolled patch
Comment #5
basvredelingThis 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.
Comment #6
basvredelingClosed the wrong issue. This needs to be open and reviewed. Will do so now.
Comment #8
basvredelingMerged, thanks for contributing @jhaskins @mallezie
Comment #9
basvredeling