2
0
forked from Wavyzz/dolibarr

NEW : add extrafield option "empty on clone" (#34866)

* NEW : add extrafield option "empty on clone"

* NEW : empty extrafield value on clone

* Fix : missing parameter in function call

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Maxime Kohlhaas
2025-08-04 16:48:11 +02:00
committed by GitHub
parent b954bc7386
commit 1a4226ff64
9 changed files with 74 additions and 33 deletions

View File

@@ -6723,17 +6723,21 @@ abstract class CommonObject
$attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey];
$attributeUnique = $extrafields->attributes[$this->table_element]['unique'][$attributeKey];
$attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey];
$attributeEmptyOnClone = $extrafields->attributes[$this->table_element]['emptyonclone'][$attributeKey];
// If we clone, we have to clean unique extrafields to prevent duplicates.
// If we clone, we have to clean extrafields having "empty on clone" option on.
// 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)) {
if (!empty($this->context['createfromclone']) && $this->context['createfromclone'] == 'createfromclone' && (!empty($attributeUnique) || !empty($attributeEmptyOnClone))) {
$new_array_options[$key] = null;
continue;
}
// If we create product combination, we have to clean unique extrafields to prevent duplicates.
// This behaviour can be prevented by external code by changing $this->context['createproductcombination'] value in hook
if (!empty($this->context['createproductcombination']) && $this->context['createproductcombination'] == 'createproductcombination' && !empty($attributeUnique)) {
$new_array_options[$key] = null;
continue;
}
// Similar code than into insertExtraFields
@@ -6755,6 +6759,7 @@ abstract class CommonObject
} else {
$new_array_options[$key] = null;
}
continue;
}
switch ($attributeType) {