From 80832877ebbb45cc1009e00be557be0835bf4adf Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Thu, 17 Aug 2017 15:21:17 +0000 Subject: [PATCH] =?UTF-8?q?N=C2=B0984=20Portal:=20Dependancies=20on=20auto?= =?UTF-8?q?complete=20fields=20now=20works=20properly.=20(Changing=20value?= =?UTF-8?q?=20on=20a=20parent=20autcomplete=20was=20not=20resetting=20valu?= =?UTF-8?q?e=20on=20a=20dependant=20autocomplete=20field)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SVN:trunk[4863] --- core/attributedef.class.inc.php | 4 ++++ .../src/forms/objectformmanager.class.inc.php | 20 +++++++++++++++++++ .../field/selectobjectfield.class.inc.php | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 4acba369f..50be39e98 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -4651,6 +4651,10 @@ class AttributeExternalKey extends AttributeDBFieldVoid $oTmpField = $oFormField; $oFormField->SetOnFinalizeCallback(function() use ($oTmpField, $oTmpAttDef, $oObject) { + /** @var $oTmpField \Combodo\iTop\Form\Field\Field */ + /** @var $oTmpAttDef \AttributeDefinition */ + /** @var $oObject \DBObject */ + // We set search object only if it has not already been set (overrided) if ($oTmpField->GetSearch() === null) { diff --git a/datamodels/2.x/itop-portal-base/portal/src/forms/objectformmanager.class.inc.php b/datamodels/2.x/itop-portal-base/portal/src/forms/objectformmanager.class.inc.php index cb8bf24ed..f4597bd71 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/forms/objectformmanager.class.inc.php +++ b/datamodels/2.x/itop-portal-base/portal/src/forms/objectformmanager.class.inc.php @@ -32,6 +32,9 @@ use \DBObject; use \DBObjectSet; use \DBSearch; use \DBObjectSearch; +use \BinaryExpression; +use \FieldExpression; +use \ScalarExpression; use \DBObjectSetComparator; use \InlineImage; use \AttributeDateTime; @@ -705,6 +708,23 @@ class ObjectFormManager extends FormManager $oField->SetSearch($oScopeOriginal); } } + // - Field that require to check if the current value is among allowed ones + if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SelectObjectField'))) + { + // Note: We can't do this in AttributeExternalKey::MakeFormField() in the Field::SetOnFinalizeCallback() because at this point we have no information about the portal scope and ignore_silos flag, hence it always applies silos. + // As a workaround we have to manually check if the field's current value is among the scope + + /** @var DBObjectSearch $oValuesScope */ + $oValuesScope = $oField->GetSearch()->DeepClone(); + $oBinaryExp = new BinaryExpression(new FieldExpression('id', $oValuesScope->GetClassAlias()), '=', new ScalarExpression( $oField->GetCurrentValue() )); + $oValuesScope->AddConditionExpression($oBinaryExp); + $oValuesSet = new DBObjectSet($oValuesScope); + + if( $oValuesSet->Count() === 0 ) + { + $oField->SetCurrentValue(null); + } + } // - Field that require processing on their subfields if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SubFormField'))) { diff --git a/sources/form/field/selectobjectfield.class.inc.php b/sources/form/field/selectobjectfield.class.inc.php index dd9f70715..b74318aaa 100644 --- a/sources/form/field/selectobjectfield.class.inc.php +++ b/sources/form/field/selectobjectfield.class.inc.php @@ -1,6 +1,6 @@ oSearch;