I'm trying to build a form that I will implement in a Twig template. For that, I'm using some HTML elements. One of them is The ChoiceType from Symfony component. I've created an array that i pass to the add method.
My wish is to display the keys in the value attribute and each value of the array in the label, thing I have failed to do
protected $lsa_types = array(
'B' => 'Boolean',
'D' => 'Date',
'F' => 'Float',
'I' => 'Integer',
'L' => 'List',
'S' => 'String',
'T' => 'Text',
);
$form->add('type', ChoiceType::class, array('choices' => $this->lsa_types,
'choice_label' => function ($value) {
return $value;
},
'choice_value' => function ($key) {
return $key;
},
'required' => true));
"choices_as_values" => trueas option of your ChoiceTypechoices_as_valuesis deprecated since the third version of symfony