N°8772 - dynamic form

This commit is contained in:
Benjamin Dalsass
2025-10-30 10:38:23 +01:00
parent 4c9373d034
commit 68d2038488
40 changed files with 854 additions and 328 deletions

View File

@@ -29,15 +29,14 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
public const OUTPUT_VALUE = 'value';
/** @inheritdoc */
public function InitOptions(array &$aOptions = []): array
public function InitBlockOptions(array &$aUserOptions): void
{
$aOptions['multiple'] = true;
$aOptions['attr'] = [
parent::InitBlockOptions($aUserOptions);
$aUserOptions['multiple'] = true;
$aUserOptions['attr'] = [
'size' => 5,
'style' => 'height: auto;',
];
return $aOptions;
}
/** @inheritdoc */
@@ -55,51 +54,18 @@ class AttributeValueChoiceFormBlock extends ChoiceFormBlock
$this->AddOutput(self::OUTPUT_VALUE, RawFormat::class);
}
/** @inheritdoc
* @throws FormBlockException
* @throws Exception
*/
public function AllowAdd(): bool
/** @inheritdoc */
public function UpdateDynamicOptions(string $sEventType = null): void
{
$bDependentOk = $this->GetInput(self::INPUT_CLASS_NAME)->Value() != '' && $this->GetInput(self::INPUT_ATTRIBUTE)->Value() != '';
$oClassName = $this->GetInput(self::INPUT_CLASS_NAME)->GetValue($sEventType);
$oAttribute = $this->GetInput(self::INPUT_ATTRIBUTE)->GetValue($sEventType);
if ($bDependentOk) {
$oAttDef = MetaModel::GetAttributeDef($this->GetInput(self::INPUT_CLASS_NAME)->Value()->__toString(), $this->GetInput(self::INPUT_ATTRIBUTE)->Value()->__toString());
try{
$oAttDef = MetaModel::GetAttributeDef(strval($oClassName), strval($oAttribute));
$aValues = $oAttDef->GetAllowedValues();
return $aValues != null;
} else {
return false;
$this->aDynamicOptions['choices'] = array_flip($aValues ?? []);
}
}
/** @inheritdoc
* @throws Exception
*/
public function UpdateOptions(): array
{
$aOptions = parent::GetOptions();
$oClassName = $this->GetInput(self::INPUT_CLASS_NAME)->Value();
if ($oClassName == '') {
return $aOptions;
}
$oAttribute = $this->GetInput(self::INPUT_ATTRIBUTE)->Value();
if ($oAttribute == '') {
return $aOptions;
}
$oAttDef = MetaModel::GetAttributeDef(strval($oClassName), strval($oAttribute));
$aValues = $oAttDef->GetAllowedValues();
if ($aValues === null) {
return $aOptions;
}
$aOptions['choices'] = array_flip($aValues ?? []);
return $aOptions;
catch(Exception){}
}
}