Cannot clone a node containing a custom field with a 'UniqueField' custom constraint set on it

Created on 15 January 2025, 3 months ago

Problem/Motivation

The module does not look for fields with 'UniqueField' constraint set on them and tries to clone them as-is without updating such fields and that causes the clone process to fail on 'duplicate entry' error on DB level and the module to be unusable on such entities.

Steps to reproduce

1. Create a new content type or update an existing one.
2. Add a new field.
3. Set a 'UniqueField' constraint on it using code.
e.g.:
$fields['my_uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->addConstraint('UniqueField', [])
->setDefaultValue(FALSE)
->setReadOnly(TRUE);

4. Create a new node using the updated content type.
5. Try to use the module to clone it.

Proposed resolution

Detect fields with such a constraint and allow the user to clone the data of the original field with a change so it will stay unique and allowed to be cloned at the same time.

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇮🇱Israel ohadm

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

Comments & Activities

Production build 0.71.5 2024