Fix some value types

This commit is contained in:
Eric Espie
2026-01-12 13:50:28 +01:00
parent 2efe80265d
commit 5c75d0ce7c
3 changed files with 21 additions and 5 deletions

View File

@@ -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

View File

@@ -37,7 +37,7 @@ class ValueTypeIcon extends AbstractLeafValueType
$sValue = utils::QuoteForPHP($aIcon['label']);
$sCode = utils::QuoteForPHP($aIcon['value']);
$sChoices .= <<<PHP
\t\t\t\t$sCode => $sValue,\n
\t\t\t\t$sValue => $sCode,\n
PHP;
}
$sChoices .= "\t\t\t]";

View File

@@ -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()