diff --git a/sources/Forms/Block/AbstractFormBlock.php b/sources/Forms/Block/AbstractFormBlock.php index 356b33829..64d91ca30 100644 --- a/sources/Forms/Block/AbstractFormBlock.php +++ b/sources/Forms/Block/AbstractFormBlock.php @@ -53,8 +53,11 @@ abstract class AbstractFormBlock $this->InitInputs(); $this->InitOutputs(); $this->aOptions = array_merge($this->aOptions, $this->InitOptions()); + $this->BuildForm(); } + abstract protected function BuildForm(); + /** * Return the form block name. * @@ -65,6 +68,17 @@ abstract class AbstractFormBlock return $this->sName; } + /** + * Return the form block options. + * Options will be passed to FormType for building. + * + * @return array + */ + public function GetOptions(): array + { + return $this->aOptions; + } + /** * Return the form block options. * Options will be passed to FormType for building. @@ -183,6 +197,15 @@ abstract class AbstractFormBlock return $this; } + public function DependsOnParent(string $sInputName, FormBlock $oParentBlock, string $sParentInputName): AbstractFormBlock + { + $oFormInput = $this->GetInput($sInputName); + $oParentFormInput = $oParentBlock->GetInput($sParentInputName); + $oFormInput->Bind($oParentFormInput); + + return $this; + } + public function HasConnections(): bool { foreach ($this->aFormInputs as $oFormInput) { diff --git a/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php b/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php index 69b25b1fc..f1fb82077 100644 --- a/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php +++ b/sources/Forms/Block/DataModel/AttributeChoiceFormBlock.php @@ -44,10 +44,10 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock /** @inheritdoc */ public function UpdateOptions(): array { - $aOptions = parent::UpdateOptions(); + $aOptions = parent::GetOptions(); $oBinding = $this->GetInput(self::INPUT_CLASS_NAME)->GetBinding(); - $oConnectionValue = $oBinding->oOutput->Value(); + $oConnectionValue = $oBinding->oSourceIO->Value(); $aAttributeCodes = \MetaModel::GetAttributesList($oConnectionValue); $aAttributeCodes = array_combine($aAttributeCodes, $aAttributeCodes) ; diff --git a/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php b/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php index 2d7b331ee..13a504ded 100644 --- a/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php +++ b/sources/Forms/Block/DataModel/AttributeValueChoiceFormBlock.php @@ -10,7 +10,6 @@ use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock; use Combodo\iTop\Forms\Block\IO\Format\AttributeIOFormat; use Combodo\iTop\Forms\Block\IO\Format\ClassIOFormat; use Combodo\iTop\Forms\Block\IO\FormInput; -use Combodo\iTop\Forms\FormType\AttributeChoiceType; use Combodo\iTop\Forms\FormType\AttributeValueChoiceType; /** @@ -47,17 +46,17 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock public function UpdateOptions(): array { - $aOptions = parent::UpdateOptions(); + $aOptions = parent::GetOptions(); $oBindingClassName = $this->GetInput(self::INPUT_CLASS_NAME)->GetBinding(); - if($oBindingClassName->oOutput->Value() === null || $oBindingClassName->oOutput->Value() == "") + if($oBindingClassName->oSourceIO->Value() === null || $oBindingClassName->oSourceIO->Value() == "") return $aOptions; - $oClassName = $oBindingClassName->oOutput->Value(); + $oClassName = $oBindingClassName->oSourceIO->Value(); $oBindingAttribute = $this->GetInput(self::INPUT_ATTRIBUTE)->GetBinding(); - if($oBindingAttribute->oOutput->Value() === null || $oBindingAttribute->oOutput->Value() == "") + if($oBindingAttribute->oSourceIO->Value() === null || $oBindingAttribute->oSourceIO->Value() == "") return $aOptions; - $oAttribute = $oBindingAttribute->oOutput->Value(); + $oAttribute = $oBindingAttribute->oSourceIO->Value(); $oAttDef = \MetaModel::GetAttributeDef(strval($oClassName), strval($oAttribute)); $aValues = $oAttDef->GetAllowedValues(); diff --git a/sources/Forms/Block/FormBlock.php b/sources/Forms/Block/FormBlock.php index 06f1c01d4..bae93e3ca 100644 --- a/sources/Forms/Block/FormBlock.php +++ b/sources/Forms/Block/FormBlock.php @@ -39,4 +39,8 @@ class FormBlock extends AbstractFormBlock { return []; } + + protected function BuildForm(): void + { + } } \ No newline at end of file diff --git a/sources/Forms/Block/IO/AbstractFormIO.php b/sources/Forms/Block/IO/AbstractFormIO.php index b01bf3792..9c9df4760 100644 --- a/sources/Forms/Block/IO/AbstractFormIO.php +++ b/sources/Forms/Block/IO/AbstractFormIO.php @@ -12,10 +12,33 @@ class AbstractFormIO { private AbstractFormBlock $oOwnerBlock; + private string $sName; + private string $sType; - public function SetOwnerBlock(AbstractFormBlock $oOwnerBlock): void + public function __construct(string $sName, string $sType) { - $this->oOwnerBlock = $oOwnerBlock; + $this->sName = $sName; + $this->sType = $sType; + } + + public function GetName(): string + { + return $this->sName; + } + + public function SetName(string $sName): void + { + $this->sName = $sName; + } + + public function GetType(): string + { + return $this->sType; + } + + public function SetType(string $sType): void + { + $this->sType = $sType; } public function GetOwnerBlock(): AbstractFormBlock @@ -23,4 +46,9 @@ class AbstractFormIO return $this->oOwnerBlock; } + public function SetOwnerBlock(AbstractFormBlock $oOwnerBlock): void + { + $this->oOwnerBlock = $oOwnerBlock; + } + } \ No newline at end of file diff --git a/sources/Forms/Block/IO/FormBinding.php b/sources/Forms/Block/IO/FormBinding.php index e8f45378b..a76773126 100644 --- a/sources/Forms/Block/IO/FormBinding.php +++ b/sources/Forms/Block/IO/FormBinding.php @@ -9,7 +9,7 @@ namespace Combodo\iTop\Forms\Block\IO; class FormBinding { - public function __construct(public readonly FormInput $oInput, public readonly FormOutput $oOutput) + public function __construct(public readonly FormInput $oDestinationIO, public readonly AbstractFormIO $oSourceIO) { } diff --git a/sources/Forms/Block/IO/FormInput.php b/sources/Forms/Block/IO/FormInput.php index 57b221f61..e1eba33fd 100644 --- a/sources/Forms/Block/IO/FormInput.php +++ b/sources/Forms/Block/IO/FormInput.php @@ -10,45 +10,17 @@ use Combodo\iTop\Forms\Block\FormBlockIOException; class FormInput extends AbstractFormIO { - private string $sName; - - private string $sType; private FormBinding|null $oBinding = null; - public function __construct(string $sName, string $sType) - { - $this->sName = $sName; - $this->sType = $sType; - } - public function GetName(): string + public function Bind(AbstractFormIO $oSourceIO): void { - return $this->sName; - } - - public function SetName(string $sName): void - { - $this->sName = $sName; - } - - public function GetType(): string - { - return $this->sType; - } - - public function SetType(string $sType): void - { - $this->sType = $sType; - } - - public function Bind(FormOutput $oFormOutput): void - { - if($this->sType !== $oFormOutput->GetType()){ - throw new FormBlockIOException('Cannot connect input types incompatibles ' . $this->sName . ' to ' . $sOutputBlock->GetName() . ' ' . $sOutputName); + if($this->GetType() !== $oSourceIO->GetType()){ + throw new FormBlockIOException('Cannot connect input types incompatibles ' . $this->GetName() . ' from ' . $oSourceIO->GetOwnerBlock()->GetName() . ' ' . $oSourceIO->GetName()); } - $this->oBinding = new FormBinding($this, $oFormOutput); + $this->oBinding = new FormBinding($this, $oSourceIO); } public function GetBinding(): FormBinding @@ -58,7 +30,7 @@ class FormInput extends AbstractFormIO public function IsDataReady(string $sEventType): bool { - return $this->oBinding->oOutput->HasValue($sEventType); + return $this->oBinding->oSourceIO->HasValue($sEventType); } public function IsBound(): bool diff --git a/sources/Forms/Block/IO/FormOutput.php b/sources/Forms/Block/IO/FormOutput.php index 5e4adf3e9..4b3b9f7ef 100644 --- a/sources/Forms/Block/IO/FormOutput.php +++ b/sources/Forms/Block/IO/FormOutput.php @@ -11,40 +11,15 @@ use Symfony\Component\Form\FormEvents; class FormOutput extends AbstractFormIO { - private string $sName; - - private string $sType; - private null|AbstractOutputConverter $oConverter; private array $aValues = []; public function __construct(string $sName, string $sType, AbstractOutputConverter $oConverter = null) { - $this->sName = $sName; - $this->sType = $sType; + parent::__construct($sName, $sType); $this->oConverter = $oConverter; } - public function GetName(): string - { - return $this->sName; - } - - public function SetName(string $sName): void - { - $this->sName = $sName; - } - - public function GetType(): string - { - return $this->sType; - } - - public function SetType(string $sType): void - { - $this->sType = $sType; - } - public function ConvertValue(mixed $oData): mixed { if (is_null($this->oConverter)) { diff --git a/sources/Forms/FormBuilder/DependencyMap.php b/sources/Forms/FormBuilder/DependencyMap.php index ad33ec47c..0ad376ad5 100644 --- a/sources/Forms/FormBuilder/DependencyMap.php +++ b/sources/Forms/FormBuilder/DependencyMap.php @@ -43,8 +43,8 @@ class DependencyMap foreach ($oDependentBlock->GetInputsBindings() as $sInputName => $oBinding) { // connection information - $sOutputBlockName = $oBinding->oOutput->GetOwnerBlock()->GetName(); - $sOutputName = $oBinding->oOutput->GetName(); + $sOutputBlockName = $oBinding->oSourceIO->GetOwnerBlock()->GetName(); + $sOutputName = $oBinding->oSourceIO->GetName(); // initialize map if (!isset($this->aDependenciesMap[$sOutputBlockName])) {