Clone nested inline blocks when translating

Created on 2 December 2019, over 5 years ago
Updated 23 September 2024, 5 months ago

Problem/Motivation

I understand that this falls into the category of "Mad Science".

I am building a site with "nested" blocks. That is, several block types have entity reference fields that reference other blocks. The site then uses these nested blocks with Layout Builder. The nested blocks are set non-reusable and added to the inline_block_usage using ✨ Custom blocks created in inline forms should not be reusable Needs work .

When translating a node that has a custom layout with inline blocks, this module provides an option, "Copy blocks into translation". When we select this option, the layout is copied over. The inline blocks in the layout are cloned into new inline blocks, with the correct language code. So far, so good.

I would like the nested blocks to be cloned as well.

Proposed resolution

Modify Drupal\layout_builder_at\Plugin\Field\FieldWidget\LayoutBuilderCopyWidget::cloneEntity() so that it recursively clones inline blocks, following entity reference fields.

What could possibly go wrong? OK, we will be in big trouble if there is a loop (like a circular firing squad) of inline blocks and entity reference fields. What else could go wrong?

Remaining tasks

The code could use some clean-up:

  • Use dependency injection.
  • Handle entity reference and entity reference revision fields more consistently. Combine the two helper functions.
  • Provide more complete documentation blocks.

Other things:

  • Add some automated tests.
  • Update Drupal\layout_builder_at\EventSubscriber\SetInlineBlockDependencyWithContextTranslation so that it handles nested inline blocks.

User interface changes

None. This all happens automatically once the user enables the "Copy blocks into translation" option.

API changes

None. We will add a parameter to cloneEntity(), but that method is marked protected.

Data model changes

None

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024