Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support for input Form/Type with DataTransformer #118

Open
kornel-kedzierski opened this Issue Dec 14, 2012 · 4 comments

Comments

Projects
None yet
5 participants

Simple FormType works great, but when I add DataTransformers, docs for input becomes empty.

Contributor

pylebecq commented Mar 8, 2013

I can confirm that. There is also another thing : if an option is required but does not have a default value.

Collaborator

willdurand commented Mar 17, 2013

Tagged as "enhancement", feel free to work on it :)

odoucet commented Dec 2, 2013

Small work on this task : doc is empty because the formType cannot be created. This is because when you use dataTransformers, you have to extend setDefaultOptions() and require an option 'em' as ObjectManager.
NelmioDocType does not pass it at creation, and silently dropped the error (better have an empty doc for this form, than no doc at all).

So this works:

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'My\APIBundle\Entity\User',
            'csrf_protection'   => false,
        ));
    }

And this does not :

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'My\APIBundle\Entity\User',
            'csrf_protection'   => false,
        ))
        ->setRequired(array(
                'em'
        ))
        ->setAllowedTypes(array(
                'em' => 'Doctrine\Common\Persistence\ObjectManager',
            ))
        ;
    }

So to support DataTransformer, I think we need to modify Parser/FormTypeParser.php

Hi guys, I've faced the same problem. But looking at how ApiDoc bundle works for few minutes I've found a solution for my case! Here it is:

  1. First, define your form as service, it is pretty easy, suppose it is "form_alias_you_defined"
  2. Inject needed services to form (ex. EntityManager)
  3. Use your form name in ApiDoc instead of form class like this:
/**
* ...
* input = "form_alias_you_defined"
*/

Profit!
Also don't forget to read official documentation with usefull tips, like passing method (GET, POST, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment