N°8772 - test driven compiler wip

This commit is contained in:
Eric Espie
2025-12-10 16:21:31 +01:00
parent 090925e28b
commit c40e7ab10e
13 changed files with 402 additions and 54 deletions

View File

@@ -7,13 +7,69 @@
namespace Combodo\iTop\PropertyTree;
use Combodo\iTop\DesignElement;
use Combodo\iTop\Forms\Block\Base\CollectionBlock;
/**
* @since 3.3.0
*/
class CollectionOfTrees extends AbstractProperty
{
public function ToPHP(&$aPHPFragments = []): string
protected ?string $sButtonLabel;
/**
* @inheritDoc
*/
public function InitFromDomNode(DesignElement $oDomNode, string $sParentId = ''): void
{
return '';
parent::InitFromDomNode($oDomNode, $sParentId);
$oPropertyTreeFactory = PropertyTreeFactory::GetInstance();
$this->sButtonLabel = $oDomNode->GetChildText('button-label');
// read child properties
foreach ($oDomNode->GetUniqueElement('prototype')->childNodes as $oNode) {
if ($oNode instanceof DesignElement) {
$this->AddChild($oPropertyTreeFactory->CreateNodeFromDom($oNode, $this->sId));
}
}
}
public function ToPHPFormBlock(&$aPHPFragments = []): string
{
$sFormBlockClass = CollectionBlock::class;
$sSubTreeClass = 'SubFormFor__'.$this->sId;
// Create the collection node
$sLocalPHP = <<<PHP
\$this->Add('$this->sId', '$sFormBlockClass', [
'label' => '$this->sLabel',
'button_label' => '$this->sButtonLabel',
'block_entry_type' => '$sSubTreeClass',
]);
PHP;
$sSubClassPHP = <<<PHP
class SubFormFor__$this->sId extends Combodo\iTop\Forms\Block\Base\FormBlock
{
protected function BuildForm(): void
{
PHP;
foreach ($this->aChildren as $oProperty) {
$sSubClassPHP .= "\n".$oProperty->ToPHPFormBlock($aPHPFragments);
}
$sSubClassPHP .= <<<PHP
}
}
PHP;
$aPHPFragments[] = $sSubClassPHP;
return $sLocalPHP;
}
}