I want to store an array of 9 checkboxes each related to same entity in my database.
Exemple of desired data
['0','0','1','1','1','1','1','1','1'] #Array[]|length = 9
['1','0','0','0','0','0','0','0','0']
['0','1','0','0','0','0','0','0','0']
['1','1','0','0','0','0','0','0','0']
['2','0','0','0','0','0','0','0','0']
['0','2','0','0','0','0','0','0','0']
['0','0','2','0','0','0','0','0','0']
['0','0','2','1','0','0','0','0','0']
['1','0','2','0','0','0','0','0','0']
Here that's i've got for these corresponding examples
['0','0']
['1','0']
['0','1']
['1','1']
['2','0']
['0','0']
['0','2']
['0','0','2'] #something i cant understand
['1','0','2']
I use basic ChoiceType
$builder
->add('recipe', ChoiceType::class, [
'choices' => [],
'multiple' => true,
'expanded' => true,
'label' => 'Craft',
])
;
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$craft = $event->getData();
$recipe = $craft['recipe'];
dump($recipe); # good at this point
});
$builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
$craft = $event->getData();
$recipe = $craft['recipe'];
dump($recipe); # bad array...
});
Accorded to symfony documentation, between these two events, data get normalized. (reference)
I would like to customize normalization step accorded to my FormType, and only thing ive found after few hours is file located at symfony/form/ChoiceList/ArrayChoiceList.php which can be my problem. (ArrayChoiceList on github)