Merge pull request #20233 from marc-dll/13.0_FIX_clone_with_unique_extrafields

FIX: object cloning: set unique extrafield values to null to prevent duplicates
This commit is contained in:
Laurent Destailleur 2022-04-01 14:49:25 +02:00 committed by GitHub
commit 0c27578e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5307,8 +5307,15 @@ abstract class CommonObject
$attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey];
$attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey];
$attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey];
$attributeUnique = $extrafields->attributes[$this->table_element]['unique'][$attributeKey];
$attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey];
// If we clone, we have to clean unique extrafields to prevent duplicates.
// This behaviour can be prevented by external code by changing $this->context['createfromclone'] value in createFrom hook
if (! empty($this->context['createfromclone']) && $this->context['createfromclone'] == 'createfromclone' && ! empty($attributeUnique)) {
$new_array_options[$key] = null;
}
// Similar code than into insertExtraFields
if ($attributeRequired)
{