/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
// Adding dynamically created code field
$nameOptions = ['label' => 'sylius.form.locale.name'];
$locale = $event->getData();
if ($locale instanceof LocaleInterface && null !== $locale->getCode()) {
$nameOptions['disabled'] = true;
} else {
$nameOptions['choices'] = $this->getAvailableLocales();
}
$nameOptions['choices_as_values'] = false;
$form = $event->getForm();
$form->add('code', 'locale', $nameOptions);
});
}