SDK Form demonstrator use symfonycast/dynamic_forms

This commit is contained in:
Eric Espie
2025-04-15 09:45:17 +02:00
parent 6acd687e05
commit 2d13aa76d0

View File

@@ -17,15 +17,19 @@ class ValuesFromAttcodeType extends AbstractType
return SymfonyChoiceType::class;
}
public static function BuildSubField(DependentField $oDependentField, string $sQuery, string $sGroupByAttCode, array $aFormOptions = []): void
public static function BuildSubField(DependentField $oDependentField, string $sQuery, ?string $sGroupByAttCode, array $aFormOptions = []): void
{
$oModelReflection = new \ModelReflectionRuntime();
$oQuery = $oModelReflection->GetQuery($sQuery);
$sClass = $oQuery->GetClass();
$oAttDef = \MetaModel::GetAttributeDef($sClass, $sGroupByAttCode);
if (is_null($sGroupByAttCode)) {
$aFormOptions['choices'] = [];
} else {
$oModelReflection = new \ModelReflectionRuntime();
$oQuery = $oModelReflection->GetQuery($sQuery);
$sClass = $oQuery->GetClass();
$oAttDef = \MetaModel::GetAttributeDef($sClass, $sGroupByAttCode);
//$aFormOptions['inherit_data'] = true;
$aFormOptions['choices'] = array_flip($oAttDef->GetAllowedValues() ?? []);
//$aFormOptions['inherit_data'] = true;
$aFormOptions['choices'] = array_flip($oAttDef->GetAllowedValues() ?? []);
}
$aFormOptions['multiple'] = true;
$oDependentField->add(ValuesFromAttcodeType::class, $aFormOptions);