mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
SDK Form demonstrator limit events callbacks
This commit is contained in:
@@ -12,7 +12,6 @@ use Symfony\Component\Form\AbstractType;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
use Symfony\Component\Form\FormEvents;
|
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
@@ -20,20 +19,7 @@ class AttCodeGroupByType extends AbstractType
|
|||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
|
$builder->addEventListener($options['hook_type'], function (FormEvent $event) use ($options): void {
|
||||||
\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 {
|
|
||||||
\IssueLog::Info($event->getForm()->getName().' POST_SUBMIT');
|
\IssueLog::Info($event->getForm()->getName().' POST_SUBMIT');
|
||||||
call_user_func($options['callback'], $event);
|
call_user_func($options['callback'], $event);
|
||||||
});
|
});
|
||||||
@@ -49,6 +35,8 @@ class AttCodeGroupByType extends AbstractType
|
|||||||
parent::configureOptions($resolver);
|
parent::configureOptions($resolver);
|
||||||
$resolver->setDefined('callback')
|
$resolver->setDefined('callback')
|
||||||
->setAllowedTypes('callback', 'callable');
|
->setAllowedTypes('callback', 'callable');
|
||||||
|
$resolver->setDefined('hook_type')
|
||||||
|
->setAllowedTypes('hook_type', 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void
|
public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class ValuesFromAttcodeType extends AbstractType
|
|||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
parent::configureOptions($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
|
public static function BuildSubField(FormInterface $oForm, string $sName, array $aData, array $aFormOptions = []): void
|
||||||
@@ -56,9 +57,14 @@ class ValuesFromAttcodeType extends AbstractType
|
|||||||
$sClass = $oQuery->GetClass();
|
$sClass = $oQuery->GetClass();
|
||||||
$sAttCode = $aData['group_by'];
|
$sAttCode = $aData['group_by'];
|
||||||
if (\MetaModel::IsValidAttCode($sClass, $sAttCode)) {
|
if (\MetaModel::IsValidAttCode($sClass, $sAttCode)) {
|
||||||
$oAttDef = \MetaModel::GetAttributeDef($sClass, $sAttCode);
|
$aAllowed = $oModelReflection->GetAllowedValues_att($sClass, $sAttCode);
|
||||||
|
if (is_array($aAllowed))
|
||||||
$aFormOptions['choices'] = array_flip($oAttDef->GetAllowedValues() ?? []);
|
{
|
||||||
|
$aValues = array_flip($aAllowed);
|
||||||
|
} else {
|
||||||
|
$aValues = [];
|
||||||
|
}
|
||||||
|
$aFormOptions['choices'] = $aValues;
|
||||||
} else {
|
} else {
|
||||||
$aFormOptions['choices'] = [];
|
$aFormOptions['choices'] = [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user