N°8771 - Add Symfony form component to iTop core

- IO debug
This commit is contained in:
Benjamin Dalsass
2025-10-28 15:22:29 +01:00
parent c2fcf4144b
commit 5d335b39d2
36 changed files with 1348 additions and 468 deletions

View File

@@ -7,12 +7,15 @@
namespace Combodo\iTop\Forms\Block\DataModel;
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
use Combodo\iTop\Forms\Block\FormBlockException;
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\Block\IO\FormOutput;
use Combodo\iTop\Forms\Converter\StringToAttributeConverter;
use Combodo\iTop\Forms\FormType\AttributeChoiceType;
use Combodo\iTop\Forms\Block\IO\Converter\StringToAttributeConverter;
use Combodo\iTop\Forms\FormType\AttributeFormType;
use CoreException;
use MetaModel;
/**
* Form block for choice of class attributes.
@@ -27,6 +30,14 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock
// outputs
public const OUTPUT_ATTRIBUTE = 'attribute';
/** @inheritdoc */
public function InitOptions(): array
{
$aOptions = parent::InitOptions();
$aOptions['placeholder'] = 'Select an attribute...';
return $aOptions;
}
/** @inheritdoc */
public function InitInputs(): void
{
@@ -41,15 +52,27 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock
$this->AddOutput(new FormOutput(self::OUTPUT_ATTRIBUTE, AttributeIOFormat::class, new StringToAttributeConverter()));
}
/** @inheritdoc */
/** @inheritdoc
* @throws FormBlockException
*/
public function AllowAdd(): bool
{
return $this->GetInput(self::INPUT_CLASS_NAME)->Value() != '';
}
/** @inheritdoc
* @throws FormBlockException
* @throws CoreException
*/
public function UpdateOptions(): array
{
$aOptions = parent::GetOptions();
$oBinding = $this->GetInput(self::INPUT_CLASS_NAME)->GetBinding();
$oConnectionValue = $oBinding->oSourceIO->Value();
$oValue = $this->GetInput(self::INPUT_CLASS_NAME)->Value();
if($oValue == '')
return $aOptions;
$aAttributeCodes = \MetaModel::GetAttributesList($oConnectionValue);
$aAttributeCodes = MetaModel::GetAttributesList($oValue);
$aAttributeCodes = array_combine($aAttributeCodes, $aAttributeCodes) ;
$aOptions['choices'] = $aAttributeCodes;
@@ -59,6 +82,6 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock
/** @inheritdoc */
public function GetFormType(): string
{
return AttributeChoiceType::class;
return AttributeFormType::class;
}
}

View File

@@ -7,10 +7,16 @@
namespace Combodo\iTop\Forms\Block\DataModel;
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
use Combodo\iTop\Forms\Block\FormBlockException;
use Combodo\iTop\Forms\Block\IO\Converter\StringToAttributeConverter;
use Combodo\iTop\Forms\Block\IO\Format\AttributeIOFormat;
use Combodo\iTop\Forms\Block\IO\Format\ClassIOFormat;
use Combodo\iTop\Forms\Block\IO\Format\RawFormat;
use Combodo\iTop\Forms\Block\IO\FormInput;
use Combodo\iTop\Forms\FormType\AttributeValueChoiceType;
use Combodo\iTop\Forms\Block\IO\FormOutput;
use Combodo\iTop\Forms\FormType\AttributeValueFormType;
use Exception;
use MetaModel;
/**
* Form block for choice of class attribute values.
@@ -23,13 +29,15 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
public const INPUT_CLASS_NAME = 'class_name';
public const INPUT_ATTRIBUTE = 'attribute';
// Outputs
public const OUTPUT_VALUE = 'value';
/** @inheritdoc */
public function InitOptions(array &$aOptions = []): array
{
$aOptions['multiple'] = true;
$aOptions['required'] = false;
$aOptions['attr'] = [
'size' => 10,
'size' => 5,
'style' => 'height: auto;'
];
@@ -44,23 +52,52 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
$this->AddInput(new FormInput(self::INPUT_ATTRIBUTE, AttributeIOFormat::class));
}
/** @inheritdoc */
public function InitOutputs(): void
{
parent::InitOutputs();
$this->AddOutput(new FormOutput(self::OUTPUT_VALUE, RawFormat::class));
}
/** @inheritdoc
* @throws FormBlockException
* @throws Exception
*/
public function AllowAdd(): bool
{
$bDependentOk = $this->GetInput(self::INPUT_CLASS_NAME)->Value() != '' && $this->GetInput(self::INPUT_ATTRIBUTE)->Value() != '';
if($bDependentOk) {
$oAttDef = MetaModel::GetAttributeDef($this->GetInput(self::INPUT_CLASS_NAME)->Value()->__toString(), $this->GetInput(self::INPUT_ATTRIBUTE)->Value()->__toString());
$aValues = $oAttDef->GetAllowedValues();
return $aValues != null;
}
else{
return false;
}
}
/** @inheritdoc
* @throws Exception
*/
public function UpdateOptions(): array
{
$aOptions = parent::GetOptions();
$oBindingClassName = $this->GetInput(self::INPUT_CLASS_NAME)->GetBinding();
if($oBindingClassName->oSourceIO->Value() === null || $oBindingClassName->oSourceIO->Value() == "")
$oClassName = $this->GetInput(self::INPUT_CLASS_NAME)->Value();
if($oClassName == '')
return $aOptions;
$oClassName = $oBindingClassName->oSourceIO->Value();
$oBindingAttribute = $this->GetInput(self::INPUT_ATTRIBUTE)->GetBinding();
if($oBindingAttribute->oSourceIO->Value() === null || $oBindingAttribute->oSourceIO->Value() == "")
$oAttribute = $this->GetInput(self::INPUT_ATTRIBUTE)->Value();
if($oAttribute == '')
return $aOptions;
$oAttribute = $oBindingAttribute->oSourceIO->Value();
$oAttDef = \MetaModel::GetAttributeDef(strval($oClassName), strval($oAttribute));
$oAttDef = MetaModel::GetAttributeDef(strval($oClassName), strval($oAttribute));
$aValues = $oAttDef->GetAllowedValues();
if($aValues === null)
return $aOptions;
$aOptions['choices'] = array_flip($aValues);
return $aOptions;
@@ -69,7 +106,7 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
/** @inheritdoc */
public function GetFormType(): string
{
return AttributeValueChoiceType::class;
return AttributeValueFormType::class;
}
}

View File

@@ -6,21 +6,28 @@
namespace Combodo\iTop\Forms\Block\DataModel;
use Combodo\iTop\Forms\Block\Base\StringFormBlock;
use Combodo\iTop\Forms\Block\Base\TextAreaFormBlock;
use Combodo\iTop\Forms\Block\IO\Format\ClassIOFormat;
use Combodo\iTop\Forms\Block\IO\FormOutput;
use Combodo\iTop\Forms\Converter\OqlToClassConverter;
use Combodo\iTop\Forms\Block\IO\Converter\OqlToClassConverter;
use Combodo\iTop\Forms\FormType\OqlFormType;
/**
* Form block for oql expression.
*
* @package DataModel
*/
class OqlFormBlock extends StringFormBlock
class OqlFormBlock extends TextAreaFormBlock
{
// outputs
public const OUTPUT_SELECTED_CLASS = 'selected_class';
/** @inheritdoc */
public function GetFormType(): string
{
return OqlFormType::class;
}
/** @inheritdoc */
public function InitOutputs(): void
{
@@ -28,4 +35,14 @@ class OqlFormBlock extends StringFormBlock
$this->AddOutput(new FormOutput(self::OUTPUT_SELECTED_CLASS, ClassIOFormat::class, new OqlToClassConverter()));
}
/** @inheritdoc */
public function InitOptions(): array
{
$aOptions = parent::InitOptions();
$aOptions['with_ai_button'] = true;
return $aOptions;
}
}