diff --git a/sources/PropertyTree/Property.php b/sources/PropertyTree/Property.php index a5abd29c4c..99982854d2 100644 --- a/sources/PropertyTree/Property.php +++ b/sources/PropertyTree/Property.php @@ -31,10 +31,16 @@ class Property extends AbstractProperty public function ToPHPFormBlock(&$aPHPFragments = []): string { $sFormBlockClass = $this->oValueType->GetFormBlockClass(); + + $sInputs = ''; + foreach ($this->oValueType->GetInputs() as $sInput => $sValue) { + $sInputs .= "\n ->SetInputValue('$sInput', '$sValue')"; + } + return <<Add('$this->sId', '$sFormBlockClass', [ 'label' => '$this->sLabel', - ]); + ]){$sInputs}; PHP; } diff --git a/sources/PropertyTree/PropertyTree.php b/sources/PropertyTree/PropertyTree.php index d48bd3a443..eb1e55148d 100644 --- a/sources/PropertyTree/PropertyTree.php +++ b/sources/PropertyTree/PropertyTree.php @@ -52,6 +52,11 @@ PHP; $aPHPFragments[] = $sLocalPHP; if ($bIsRoot) { + // $sOutputPHP = <<GetFormBlockClass(); + $oBlockNode = new $sBlockNodeClass('foo'); + foreach ($oBlockNode->GetInputs() as $oInput) { + $sInputName = $oInput->GetName(); + $sInputValue = $oDomNode->GetChildText($sInputName); + if (utils::IsNotNullOrEmptyString($sInputValue)) { + $this->aInputs[$sInputName] = $sInputValue; + } + } + } + public function GetInputs(): array + { + return $this->aInputs; } } diff --git a/sources/PropertyTree/ValueType/ValueTypeClassAttribute.php b/sources/PropertyTree/ValueType/ValueTypeClassAttribute.php index 3c5751beb2..f3ffc6a0a2 100644 --- a/sources/PropertyTree/ValueType/ValueTypeClassAttribute.php +++ b/sources/PropertyTree/ValueType/ValueTypeClassAttribute.php @@ -7,7 +7,9 @@ namespace Combodo\iTop\PropertyTree\ValueType; +use Combodo\iTop\DesignElement; use Combodo\iTop\Forms\Block\DataModel\AttributeChoiceFormBlock; +use utils; /** * @since 3.3.0 diff --git a/sources/PropertyTree/ValueType/ValueTypeFactory.php b/sources/PropertyTree/ValueType/ValueTypeFactory.php index 545398f1d9..d8198dd97c 100644 --- a/sources/PropertyTree/ValueType/ValueTypeFactory.php +++ b/sources/PropertyTree/ValueType/ValueTypeFactory.php @@ -29,6 +29,12 @@ class ValueTypeFactory return static::$oInstance; } + /** + * @param \Combodo\iTop\DesignElement $oDomNode + * + * @return \Combodo\iTop\PropertyTree\ValueType\AbstractValueType + * @throws \Combodo\iTop\PropertyTree\PropertyTreeException + */ public function CreateValueTypeFromDomNode(DesignElement $oDomNode): AbstractValueType { $sNodeType = $oDomNode->getAttribute('xsi:type'); diff --git a/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/TestFormsCompiler.php b/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/TestFormsCompiler.php index f00fcd98b6..b18e658155 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/TestFormsCompiler.php +++ b/tests/php-unit-tests/unitary-tests/sources/Forms/Compiler/TestFormsCompiler.php @@ -268,6 +268,35 @@ PHP, 'sMessage' => '', ], + 'Input static' => [ + 'sXMLContent' => << + + + + + + Contact + + + + +XML, + 'sExpectedPHP' => <<Add('class_attribute_property', 'Combodo\iTop\Forms\Block\DataModel\AttributeChoiceFormBlock', [ + 'label' => 'UI:ClassAttribute', + ]) + ->SetInputValue('class', 'Contact'); + } +} +PHP, + 'sMessage' => '', + ], + 'test' => [ 'sXMLContent' => <<