diff --git a/sources/FormType/Orm/AttCodeGroupByType.php b/sources/FormType/Orm/AttCodeGroupByType.php index e451d7f6a3..5055418de5 100644 --- a/sources/FormType/Orm/AttCodeGroupByType.php +++ b/sources/FormType/Orm/AttCodeGroupByType.php @@ -22,11 +22,11 @@ class AttCodeGroupByType extends AbstractType { $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) { \IssueLog::Info($event->getForm()->getName().' PRE_SET_DATA'); - call_user_func($options['callback'], $event); }); $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) { @@ -51,9 +51,11 @@ class AttCodeGroupByType extends AbstractType ->setAllowedTypes('callback', 'callable'); } - public static function BuildSubField(FormInterface $oForm, string $sName, string $sQuery, array $aFormOptions = []): void + public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void { - $aFormOptions['choices'] = self::GetGroupByOptions($sQuery); + \IssueLog::Info('AttCodeGroupByType BuildSubField data: '.var_export($aData, true)); + + $aFormOptions['choices'] = self::GetGroupByOptions($aData['query']); $aFormOptions['multiple'] = false; $oForm->add($sName, AttCodeGroupByType::class, $aFormOptions); } diff --git a/sources/FormType/Orm/QueryType.php b/sources/FormType/Orm/QueryType.php index 8741489ca6..436183cdd4 100644 --- a/sources/FormType/Orm/QueryType.php +++ b/sources/FormType/Orm/QueryType.php @@ -17,17 +17,19 @@ class QueryType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - parent::buildForm($builder, $options); - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $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) { + + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options): void { \IssueLog::Info($event->getForm()->getName().' POST_SET_DATA'); }); + $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { \IssueLog::Info($event->getForm()->getName().' PRE_SUBMIT'); }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { + + $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($options): void { \IssueLog::Info($event->getForm()->getName().' POST_SUBMIT'); }); } diff --git a/sources/FormType/Orm/ValuesFromAttcodeType.php b/sources/FormType/Orm/ValuesFromAttcodeType.php index 2bd395a12e..96a4e85d79 100644 --- a/sources/FormType/Orm/ValuesFromAttcodeType.php +++ b/sources/FormType/Orm/ValuesFromAttcodeType.php @@ -13,6 +13,7 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use utils; class ValuesFromAttcodeType extends AbstractType { @@ -42,17 +43,25 @@ class ValuesFromAttcodeType extends AbstractType parent::configureOptions($resolver); } - public static function BuildSubField(FormInterface $oForm, string $sName, string $sQuery, ?string $sGroupByAttCode, array $aFormOptions = []): void + public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void { - if (is_null($sGroupByAttCode)) { + \IssueLog::Info("ValuesFromAttcodeType BuildSubField data: ".var_export($aData, true)); + + + if (utils::IsNullOrEmptyString($aData['group_by'] ?? null)) { return; } else { $oModelReflection = new \ModelReflectionRuntime(); - $oQuery = $oModelReflection->GetQuery($sQuery); + $oQuery = $oModelReflection->GetQuery($aData['query']); $sClass = $oQuery->GetClass(); - $oAttDef = \MetaModel::GetAttributeDef($sClass, $sGroupByAttCode); + $sAttCode = $aData['group_by']; + if (\MetaModel::IsValidAttCode($sClass, $sAttCode)) { + $oAttDef = \MetaModel::GetAttributeDef($sClass, $sAttCode); - $aFormOptions['choices'] = array_flip($oAttDef->GetAllowedValues() ?? []); + $aFormOptions['choices'] = array_flip($oAttDef->GetAllowedValues() ?? []); + } else { + $aFormOptions['choices'] = []; + } } $aFormOptions['multiple'] = true; $aFormOptions['required'] = false;