Last active
November 13, 2019 10:23
-
-
Save FabianSchmick/53a9edc7efe1f6459c565b47ccf3386b to your computer and use it in GitHub Desktop.
Change Symfony Form-field in Form-event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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