diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 0f70dd915..746bac4f3 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -4050,7 +4050,7 @@ class AttributeExternalKey extends AttributeDBFieldVoid { $oFormField->SetChoices($this->GetAllowedValues($oObject->ToArgsForQuery())); } - + // If ExtKey is mandatory, we add a validator to ensure that the value 0 is not selected if ($oObject->GetAttributeFlags($this->GetCode()) & OPT_ATT_MANDATORY) { @@ -6500,16 +6500,16 @@ class AttributeCustomFields extends AttributeDefinition /** * @param DBObject $oHostObject - * @param ormCustomFieldsValue|null $oValue + * @param array|null $aValues * @return CustomFieldsHandler */ - public function GetHandler(DBObject $oHostObject, ormCustomFieldsValue $oValue = null) + public function GetHandler(DBObject $oHostObject, $aValues = null) { $sHandlerClass = $this->Get('handler_class'); $oHandler = new $sHandlerClass($oHostObject, $this->GetCode()); - if (!is_null($oValue)) + if (!is_null($aValues)) { - $oHandler->SetCurrentValues($oValue->GetValues()); + $oHandler->SetCurrentValues($aValues); } return $oHandler; } @@ -6581,7 +6581,8 @@ class AttributeCustomFields extends AttributeDefinition */ public function GetForm(DBObject $oHostObject, $sFormPrefix = null) { - $oHandler = $this->GetHandler($oHostObject, $oHostObject->Get($this->GetCode())); + $oValue = $oHostObject->Get($this->GetCode()); + $oHandler = $this->GetHandler($oHostObject, $oValue->GetValues()); $sFormId = is_null($sFormPrefix) ? 'cf_'.$this->GetCode() : $sFormPrefix.'_cf_'.$this->GetCode(); $oHandler->BuildForm($sFormId); return $oHandler->GetForm(); @@ -6608,14 +6609,18 @@ class AttributeCustomFields extends AttributeDefinition */ public function WriteValue(DBObject $oHostObject, ormCustomFieldsValue $oValue = null) { - $oHandler = $this->GetHandler($oHostObject, $oHostObject->Get($this->GetCode())); if (is_null($oValue)) { + $oHandler = $this->GetHandler($oHostObject); $aValues = array(); } else { - $aValues = $oValue->GetValues(); + // Pass the values through the form to make sure that they are correct + $oHandler = $this->GetHandler($oHostObject, $oValue->GetValues()); + $oHandler->BuildForm(''); + $oForm = $oHandler->GetForm(); + $aValues = $oForm->GetCurrentValues(); } return $oHandler->WriteValues($aValues); } @@ -6630,7 +6635,7 @@ class AttributeCustomFields extends AttributeDefinition { try { - $oHandler = $this->GetHandler($oHostObject, $value); + $oHandler = $this->GetHandler($oHostObject, $value->GetValues()); $oHandler->BuildForm(''); $oForm = $oHandler->GetForm(); $oForm->Validate(); @@ -6661,7 +6666,8 @@ class AttributeCustomFields extends AttributeDefinition */ public function DeleteValue(DBObject $oHostObject) { - $oHandler = $this->GetHandler($oHostObject, $oHostObject->Get($this->GetCode())); + $oValue = $oHostObject->Get($this->GetCode()); + $oHandler = $this->GetHandler($oHostObject, $oValue->GetValues()); return $oHandler->DeleteValues(); } diff --git a/core/ormcustomfieldsvalue.class.inc.php b/core/ormcustomfieldsvalue.class.inc.php index 5720560f1..b5d108a6c 100644 --- a/core/ormcustomfieldsvalue.class.inc.php +++ b/core/ormcustomfieldsvalue.class.inc.php @@ -59,21 +59,21 @@ class ormCustomFieldsValue public function GetAsHTML($bLocalize = true) { $oAttDef = MetaModel::GetAttributeDef(get_class($this->oHostObject), $this->sAttCode); - $oHandler = $oAttDef->GetHandler($this->oHostObject, $this); + $oHandler = $oAttDef->GetHandler($this->oHostObject, $this->GetValues()); return $oHandler->GetAsHTML($this->aCurrentValues, $bLocalize); } public function GetAsXML($bLocalize = true) { $oAttDef = MetaModel::GetAttributeDef(get_class($this->oHostObject), $this->sAttCode); - $oHandler = $oAttDef->GetHandler($this->oHostObject, $this); + $oHandler = $oAttDef->GetHandler($this->oHostObject, $this->GetValues()); return $oHandler->GetAsXML($this->aCurrentValues, $bLocalize); } public function GetAsCSV($sSeparator = ',', $sTextQualifier = '"', $bLocalize = true) { $oAttDef = MetaModel::GetAttributeDef(get_class($this->oHostObject), $this->sAttCode); - $oHandler = $oAttDef->GetHandler($this->oHostObject, $this); + $oHandler = $oAttDef->GetHandler($this->oHostObject, $this->GetValues()); return $oHandler->GetAsCSV($this->aCurrentValues, $sSeparator = ',', $sTextQualifier = '"', $bLocalize = true); } @@ -86,7 +86,7 @@ class ormCustomFieldsValue public function GetForTemplate($sVerb, $bLocalize = true) { $oAttDef = MetaModel::GetAttributeDef(get_class($this->oHostObject), $this->sAttCode); - $oHandler = $oAttDef->GetHandler($this->oHostObject, $this); + $oHandler = $oAttDef->GetHandler($this->oHostObject, $this->GetValues()); return 'template...verb='.$sVerb.' sur "'.json_encode($this->aCurrentValues).'"'; }