From 7fb2b1a7695f2f81ee13e3deb9cb4b3c31e750fd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 16 Sep 2018 22:30:13 +0200 Subject: [PATCH] Fix reset extrafields that must be unique when cloning --- .../template/class/myobject.class.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 2da97f5b800..c5355958833 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -202,7 +202,7 @@ class MyObject extends CommonObject */ public function createFromClone(User $user, $fromid) { - global $hookmanager, $langs; + global $langs, $hookmanager, $extrafields; $error = 0; dol_syslog(__METHOD__, LOG_DEBUG); @@ -222,6 +222,20 @@ class MyObject extends CommonObject $object->ref = "copy_of_".$object->ref; $object->title = $langs->trans("CopyOf")." ".$object->title; // ... + // Clear extrafields that are unique + if (is_array($object->array_options) && count($object->array_options) > 0) + { + $extrafields->fetch_name_optionals_label($this->element); + foreach($object->array_options as $key => $option) + { + $shortkey = preg_replace('/options_/', '', $key); + if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey])) + { + //var_dump($key); var_dump($clonedObj->array_options[$key]); exit; + unset($object->array_options[$key]); + } + } + } // Create clone $object->context['createfromclone'] = 'createfromclone';