Alsatian
Alsatian

Reputation: 3135

Get FormField passed options within a FormEvent

In a Symfony project, I have a Form EventSubscriber acting on several forms.

It aims to disable each field which is already filled.

In the Subscriber when I use:

$childOptions = $child->getConfig()->getOptions();

I receive all resolved options for a child, I want to get only those passed during the form building. (Because form some FormTypes (i.o. DocumentType) it is not possible to reinject all resolved options, some of them causes troubles).

This is one example of many use cases, another example could be : Alsatian\FormBundle ExtensibleSubscriber

-> A formsuscriber to make AJAX submitted choices acceptacles for Choice/Entity/Document Types. At this time, as you can see, I choosed to only take a couple of resolved options, but I'm not satisfied with this solution.

Upvotes: 4

Views: 509

Answers (1)

mcfedr
mcfedr

Reputation: 7975

Sounds like you need to change your approach.

Maybe make a custom form type, and some of the options to it should be the options to create the original type, similar to how CollectionType works.

Maybe it looks a bit like this:

->add('entity', AjaxType::class,array( 'ajax_type' => EntityType:class, 'ajax_options' => [ 'class' => 'AppBundle:User', 'choice_label' => 'username', ] ))

That type can add the event that listens for the data and decides what to do.

Upvotes: 1

Related Questions