Reputation: 885
I'm currently trying to access to my form config (and its options) in a PRE_SUBMIT FormEvent callback. However, when I'm doing that for example :
<?php
// This is my callback function for the PRE_SUBMIT event on a formtype element
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
[...]
$myConfig = $form->get('my_form_element_child')->getConfig()->get('my_option');
?>
It raises an exception saying :
FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.
Actually, I can understand why : it is because the form data is going to be submitted. However, it is a problem for me. Indeed, I need to find a way to create other fields in my form based on some config options, when the data is already entered by the user but before the data gets "handled" by the controller.
Any idea on how to do that?
Thank you !
Upvotes: 0
Views: 924
Reputation: 81
Just replace
$myConfig = $form->get('my_form_element_child')->getConfig()->get('my_option');
to
$myConfig = $form->get('my_form_element_child')->getConfig()->getOption('my_option');
Upvotes: 4