mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-17 06:18:44 +02:00
N°8772 - Sub-forms WIP
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) ;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -39,4 +39,8 @@ class FormBlock extends AbstractFormBlock
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function BuildForm(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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])) {
|
||||
|
||||
Reference in New Issue
Block a user