N°6322 Delegate \AttributeCustomFields::CheckValue to the handler

This allows to move template_id checks from BuildForm (which is called in the UI to construct the form also) to a dedicated method only called for validation
This commit is contained in:
Pierre Goiffon
2023-05-23 18:09:50 +02:00
parent 63fcf4e6f9
commit 0508608e78
2 changed files with 36 additions and 27 deletions

View File

@@ -13245,27 +13245,11 @@ class AttributeCustomFields extends AttributeDefinition
*/
public function CheckValue(DBObject $oHostObject, $value)
{
try
{
try {
$oHandler = $this->GetHandler($value->GetValues());
$oHandler->BuildForm($oHostObject, '');
$oForm = $oHandler->GetForm();
$oForm->Validate();
if ($oForm->GetValid())
{
$ret = true;
}
else
{
$aMessages = array();
foreach($oForm->GetErrorMessages() as $sFieldId => $aFieldMessages)
{
$aMessages[] = $sFieldId.': '.implode(', ', $aFieldMessages);
}
$ret = 'Invalid value: '.implode(', ', $aMessages);
}
} catch (Exception $e)
{
$ret = $oHandler->Validate($oHostObject);
} catch (Exception $e) {
$ret = $e->getMessage();
}