diff --git a/sources/PropertyType/ValueType/Leaf/ValueTypeCollectionOfValues.php b/sources/PropertyType/ValueType/Leaf/ValueTypeCollectionOfValues.php index b669d3fb12..0e1fd1da45 100644 --- a/sources/PropertyType/ValueType/Leaf/ValueTypeCollectionOfValues.php +++ b/sources/PropertyType/ValueType/Leaf/ValueTypeCollectionOfValues.php @@ -12,6 +12,7 @@ use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock; use Combodo\iTop\Forms\Block\Base\FormBlock; use Combodo\iTop\PropertyType\Serializer\XMLFormat\AbstractXMLFormat; use Combodo\iTop\PropertyType\Serializer\XMLFormat\XMLFormatFactory; +use Combodo\iTop\PropertyType\ValueType\AbstractValueType; use Combodo\iTop\PropertyType\ValueType\Branch\AbstractBranchValueType; use Combodo\iTop\PropertyType\ValueType\Leaf\AbstractLeafValueType; use Combodo\iTop\PropertyType\ValueType\ValueTypeFactory; @@ -20,6 +21,7 @@ class ValueTypeCollectionOfValues extends AbstractLeafValueType { private string $sFormBlockClass; private AbstractXMLFormat $oXMLFormat; + private AbstractValueType $oRealValueType; public function GetFormBlockClass(): string { @@ -29,17 +31,27 @@ class ValueTypeCollectionOfValues extends AbstractLeafValueType public function InitFromDomNode(DesignElement $oDomNode, ?AbstractBranchValueType $oParent = null): void { $oNode = $oDomNode->GetUniqueElement('value-type'); - $oRealValueType = ValueTypeFactory::GetInstance()->CreateValueTypeFromDomNode($oNode, $oParent); - $this->sFormBlockClass = $oRealValueType->getFormBlockClass(); + $this->oRealValueType = ValueTypeFactory::GetInstance()->CreateValueTypeFromDomNode($oNode, $oParent); + $this->sFormBlockClass = $this->oRealValueType->getFormBlockClass(); if (is_a($this->sFormBlockClass, ChoiceFormBlock::class, true)) { - $this->aFormBlockOptionsForPHP['multiple'] = 'true'; + $this->oRealValueType->aFormBlockOptionsForPHP['multiple'] = 'true'; } $oNode = $oDomNode->GetUniqueElement('xml-format'); $this->oXMLFormat = XMLFormatFactory::GetInstance()->CreateXMLFormatFromDomNode($oNode); parent::InitFromDomNode($oDomNode, $oParent); + + $this->oRealValueType->sLabel = $this->sLabel; + $this->oRealValueType->sRelevanceCondition = $this->sRelevanceCondition; + $this->oRealValueType->sId = $this->sId; + $this->oRealValueType->sIdWithPath = $this->sIdWithPath; + } + + public function ToPHPFormBlock(array &$aPHPFragments = []): string + { + return $this->oRealValueType->ToPHPFormBlock($aPHPFragments); } public function Normalize(mixed $value): mixed diff --git a/sources/PropertyType/ValueType/Leaf/ValueTypeIcon.php b/sources/PropertyType/ValueType/Leaf/ValueTypeIcon.php index 5ad0375ef8..564d25497d 100644 --- a/sources/PropertyType/ValueType/Leaf/ValueTypeIcon.php +++ b/sources/PropertyType/ValueType/Leaf/ValueTypeIcon.php @@ -37,7 +37,7 @@ class ValueTypeIcon extends AbstractLeafValueType $sValue = utils::QuoteForPHP($aIcon['label']); $sCode = utils::QuoteForPHP($aIcon['value']); $sChoices .= << $sValue,\n +\t\t\t\t$sValue => $sCode,\n PHP; } $sChoices .= "\t\t\t]"; diff --git a/tests/php-unit-tests/unitary-tests/sources/PropertyType/Compiler/FormsCompilerTest.php b/tests/php-unit-tests/unitary-tests/sources/PropertyType/Compiler/FormsCompilerTest.php index 63381afccf..a99054f894 100644 --- a/tests/php-unit-tests/unitary-tests/sources/PropertyType/Compiler/FormsCompilerTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/PropertyType/Compiler/FormsCompilerTest.php @@ -602,7 +602,9 @@ class FormFor__CollectionOfValuesTest extends Combodo\iTop\Forms\Block\Base\Form \$this->Add('coll', 'Combodo\iTop\Forms\Block\DataModel\AttributeValueChoiceFormBlock', [ 'label' => 'UI:ClassAttributeValue', 'multiple' => true, - ]); + ]) + ->SetInputValue('class', 'Contact') + ->SetInputValue('attribute', 'status'); } } PHP, @@ -883,6 +885,8 @@ PHP; $this->AssertPHPCodeIsValid($sProducedPHP); $this->assertStringStartsWith($sExpectedStart, $sProducedPHP); + + echo $sProducedPHP; } public function testCompileFormForClassSelection()