In your $langs array, you can specify key value pairs, for example:
array( 0 => 'value1', 1 => 'value2' )
Now for example. you want to pre-select value2 , you can set the data attribute on the key from value2 :
$builder->add('language', 'choice', array( 'choices' => $langs, 'expanded' => true, 'multiple' => false, 'required' => false, 'label' => false, 'data' => 1 ));
Accordingly, you can set your data attribute to your $currentLocale variable to pre-select it. Your code should look like this:
$currentLocale = "en_US"; // This is indeed sent to the formType $langs = array( 'fr_FR' => 'fr', 'en_US' => 'en' ); $builder->add('language', 'choice', array( 'choices' => $langs, 'expanded' => true, 'multiple' => false, 'required' => false, 'label' => false, 'data' => $currentLocale ));
Note: the second parameter from the add() method must be choice not language .
source share