Layout builder content blocks are duplicated on import

Created on 27 March 2024, 9 months ago

Problem/Motivation

If you export a node that has an inline content block and then import that node, the block gets created twice on the import site. Everything works, but a duplicate block is created. The duplicate is not created as a revision of the original. Two distinct blocks are created. I consider this a bug because one block essentially becomes un-referenced by the page layout and just remains there like a ghost. There's no way to delete it without deleting the entire node, which could be a problem if you are doing things like tracking entity usage (via entity_usage module).

The reason this happens is because the LayoutSection field processor plugin manually imports the node & the attached inline blocks first. Then when the entity is saved again at the end of the import process, layout_builder_entity_presave's logic determines that the blocks need to be duplicated and does so.

Steps to reproduce

  1. On the export site, create a node and edit its layout and add a simple custom content block (like a text block) and save it
  2. Export the node and import on a duplicate version of the site that doesn't already have the block or page
  3. Look at the block_content_field_data table on the import and export sites. Notice that on the import site, there's a duplicate block.

Proposed resolution

I spent a little time on this and got a bit lost in the Layout Builder code for saving the blocks. We either need to find a way to have layout builder not try duplicate the blocks that already exist, or we need to not manually create them ourselves.

Not manually creating them ourselves could mean that when exporting the inline block, we unset block_revision_id and instead serialize the block and store it in block_serialized. Then when don't need to do anything, layout builder will automatically unpack this and save the block entity and register usage of it. But the problem here is that we need the block entity to go through our import process, otherwise things like referenced media and taxonomy terms on the block won't get imported!

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

1.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024