From 305e43687dfe91cb11d3924e7b10448d2f198eb8 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Wed, 16 Apr 2025 14:55:36 +0200 Subject: [PATCH] SDK Form demonstrator limit events callbacks --- sources/FormType/Orm/AttCodeGroupByType.php | 18 +++--------------- sources/FormType/Orm/ValuesFromAttcodeType.php | 12 +++++++++--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/sources/FormType/Orm/AttCodeGroupByType.php b/sources/FormType/Orm/AttCodeGroupByType.php index 5055418de5..e6c833e45f 100644 --- a/sources/FormType/Orm/AttCodeGroupByType.php +++ b/sources/FormType/Orm/AttCodeGroupByType.php @@ -12,7 +12,6 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; -use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -20,20 +19,7 @@ class AttCodeGroupByType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) { - \IssueLog::Info($event->getForm()->getName().' PRE_SET_DATA'); - }); - - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options): void { - \IssueLog::Info($event->getForm()->getName().' POST_SET_DATA'); - call_user_func($options['callback'], $event); - }); - - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { - \IssueLog::Info($event->getForm()->getName().' PRE_SUBMIT'); - }); - - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options): void { + $builder->addEventListener($options['hook_type'], function (FormEvent $event) use ($options): void { \IssueLog::Info($event->getForm()->getName().' POST_SUBMIT'); call_user_func($options['callback'], $event); }); @@ -49,6 +35,8 @@ class AttCodeGroupByType extends AbstractType parent::configureOptions($resolver); $resolver->setDefined('callback') ->setAllowedTypes('callback', 'callable'); + $resolver->setDefined('hook_type') + ->setAllowedTypes('hook_type', 'string'); } public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void diff --git a/sources/FormType/Orm/ValuesFromAttcodeType.php b/sources/FormType/Orm/ValuesFromAttcodeType.php index 96a4e85d79..47ae54923f 100644 --- a/sources/FormType/Orm/ValuesFromAttcodeType.php +++ b/sources/FormType/Orm/ValuesFromAttcodeType.php @@ -41,6 +41,7 @@ class ValuesFromAttcodeType extends AbstractType public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); + $resolver->setDefault('attr', ['class' => 'ibo-input ibo-input-select']); } public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void @@ -56,9 +57,14 @@ class ValuesFromAttcodeType extends AbstractType $sClass = $oQuery->GetClass(); $sAttCode = $aData['group_by']; if (\MetaModel::IsValidAttCode($sClass, $sAttCode)) { - $oAttDef = \MetaModel::GetAttributeDef($sClass, $sAttCode); - - $aFormOptions['choices'] = array_flip($oAttDef->GetAllowedValues() ?? []); + $aAllowed = $oModelReflection->GetAllowedValues_att($sClass, $sAttCode); + if (is_array($aAllowed)) + { + $aValues = array_flip($aAllowed); + } else { + $aValues = []; + } + $aFormOptions['choices'] = $aValues; } else { $aFormOptions['choices'] = []; }