Fix reset extrafields that must be unique when cloning

This commit is contained in:
Laurent Destailleur 2018-09-16 22:30:13 +02:00
parent 9415486059
commit 7fb2b1a769

View File

@ -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';