hook_entity_duplicate adds all fields to duplicate

Created on 8 July 2025, 4 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

Production build 0.71.5 2024