mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°8771 - Add Symfony form component to iTop core
- IO debug
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user