Elao / ElaoJsonHttpFormBundle

Adds support for JSON POST requests to Symfony Forms
MIT License
36 stars 4 forks source link

What if setRequestHandler() is later called in a subsequent form type extension? #4

Closed mattjanssen closed 8 years ago

mattjanssen commented 9 years ago

The FormTypeHttpFoundationExtension is still loading and calling $builder->setRequestHandler(HttpFoundationRequestHandler) at some point.

How do you guarantee that your FormTypeJsonHttpFoundationExtension is built after the Symfony HttpFoundation extension? Otherwise you are only guessing at which request handler will get used. Are you just relying on the bundle order as specified in the AppKernel?

I've been trying to work this out with no success yet...

Tom32i commented 8 years ago

Form extension in Symfony bundle are designed to extend default Symfony components behaviors. I trust Symfony with processing FormTypeJsonHttpFoundationExtension after the FormTypeHttpFoundationExtension.

However, we could bypass this step and directly set the form.type_extension.form.request_handler.class parameter to Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler\JsonHttpFoundationRequestHandler.

That would be more straightforward, how do you feel about this solution?

Here's an implementation: https://github.com/Elao/ElaoJsonHttpFormBundle/pull/5

mattjanssen commented 8 years ago

Brilliant. I assume that overriding form.type_extension.form.request_handler.class is less conflict-prone than relying on the order of the AppKernel::registerBundles() array. There's always the chance that another bundle will be incompatible.

The best solution might be for Symfony's form builder to allow a stack of handlers to decide which one will handle the specific request.

Thanks for making this update.

Tom32i commented 8 years ago

Done!