Skip to content

Instantly share code, notes, and snippets.

@FabianSchmick
Last active November 13, 2019 10:23
Show Gist options
  • Save FabianSchmick/53a9edc7efe1f6459c565b47ccf3386b to your computer and use it in GitHub Desktop.
Save FabianSchmick/53a9edc7efe1f6459c565b47ccf3386b to your computer and use it in GitHub Desktop.
Change Symfony Form-field in Form-event
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
$form = $event->getForm();
$config = $form->get('groups')->getConfig(); // get the field config
$name = $config->getName(); // get the name string
$type = get_class($config->getType()->getInnerType()); // get the type class
$options = $config->getOptions(); // get the options array
$options['label'] = "Login Name"; // e.g. change the label
$form->add($name, $type, $options); // replace the field
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment