hook_entity_duplicate adds all fields to duplicate

Created on 8 July 2025, 26 days ago

Problem/Motivation

When translating a page, the Layout builder copy widget throws an error
AssertionError: Cannot load the "paragraph" entity with NULL ID. in assert() (line 262 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).

The reason when we drilled down on this, was that the hook entity_duplicate (introduced via https://www.drupal.org/project/paragraphs/issues/3495373 📌 Support duplicate hook Active ), the $duplicate->getFields() modifies the duplicate passed into it, and adds all the fields from fieldDefinition to itself.

Steps to reproduce

Using the module Layout Builder Asymmetric Translation, create a page with blocks in it, specifically a paragraph block
Add new translation.
error occurs.

Proposed resolution

Instead of iterating over getFields(), instead, iterate over fieldDefinitions().

Remaining tasks

Review patch.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇿New Zealand atowl

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

Merge Requests

Comments & Activities

  • Issue created by @atowl
  • Pipeline finished with Failed
    26 days ago
    Total: 387s
    #542524
  • 🇨🇭Switzerland berdir Switzerland

    This change doesn't make sense, it's broken and a fatal error on foreach ($fields as item)

  • 🇳🇿New Zealand atowl

    Hi @berdir,

    Could you be a bit more specific? So i could look further?

    The only test it seems to be failing is the phpunit, and thats currently failing on 8.x-1.x branch as well.

    Thanks

  • 🇮🇹Italy finex

    Hi, I'm also using Layout Builder AT and I'm experiencing the same error when translating nodes with Layout Builder, but only when a block contains a paragraph field.

    I haven't debugged as deeply as @atowl, but I can confirm that the duplicated object is indeed suspicious.

    The patch works fine for me. Now, when I try to translate a node with Layout Builder and a block containing a paragraph field, it works as expected.

    What's very strange is that if I take the same codebase and use a clean D11 installation with just a couple of languages and a simple block + paragraph setup, I can't reproduce the error. The configuration looks the same. I've also cleaned all the data tables, but maybe I'm missing something.

Production build 0.71.5 2024