Entity with a dynamic entity reference field can't be cloned using entity_clone

Created on 24 October 2023, 8 months ago
Updated 25 October 2023, 8 months ago

Problem/Motivation

Entities using a Dynamic Entity Reference field cannot be cloned using the entity_clone module.

The reason for this is because the entity_clone module check if an entity is clonable using EntityCloneClonableField::isClonable(), it check if the field is an entity reference type field and if so, what entity that field references. As the Dynamic Entity Reference field stores the target type per reference, the 'target_type' setting doesn't exist. Therefore, when entity_clone checks the storage of the referenced entity type, it throws an exception.

It may be that the appropriate solution is for the entity_clone module to handle a null entity type, though I can't think of another situation where it may be the case.

Steps to reproduce

Create a new node type.
Add a new field using the Dynamic Entity Reference type.
Create a new node of this type and ensure that the Dynamic Entity Reference field contains at least 1 value.
Attempt to clone the entity.

Proposed resolution

In DynamicEntityReferenceFieldItemList, override the getSetting($setting_name) method and check if the setting name to get is 'target_type'. If so, return the first entity in the field's referenceable entities list in the $settings property.

πŸ› Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom AlbionBrown

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

Comments & Activities

Production build 0.69.0 2024