Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate annotations form element when no explicit mapping defined #270

Closed
mpalourdio opened this issue Sep 27, 2013 · 4 comments
Closed
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@mpalourdio
Copy link
Contributor

In form generation by annotations, if in an entity we have an attribute where no mapping is defined, the Doctrine Form Element is not rendered anymore in 0.8.x

Example that worked in 0.7 :

 /**
     * @ORM\Column(type="integer")
     * @Annotation\Type("DoctrineModule\Form\Element\ObjectSelect")
     * @Annotation\Options({"target_class":"Application\Entity\Codes","label":"My codes"})
     */
 protected $code;

In controller (workaround before this module handled mapping associations)

 $form->get('code')->setOptions(
            array(
                'object_manager' => $this->em,
                'property'       => 'descrip',
                'find_method'    => array(
                    'name'   => 'findAll',
                ),
            )
        );

This used to work, and the form element was correctly hydrated with DoctrineModule\Stdlib\Hydrator\DoctrineObject

Now, as annotations handle $em, we can do :

**
     * @ORM\Column(type="integer")
     * @Annotation\Type("DoctrineModule\Form\Element\ObjectSelect")
     * @Annotation\Options({
     *      "target_class":"Application\Entity\Codes",
     *      "label":"My Code",
     *      "find_method":{"name" : "findAll"}
     * })
     */
    protected $code;

But unfortunately, as mapping association is not defined on this attribute, the ObjectSelect is not generated. It generates an input type="text", and the value is hydrated

$form->add(array(
                'name'    => 'parent',
                'type'    => 'DoctrineModule\Form\Element\ObjectSelect',
                'options' => array(
                    'label'          => My Code',
                    'target_class'   => 'Application\Entity\Codes',
                    'object_manager' => $this->em,
                    'property'       => 'descrip',
                    'find_method'    => array(
                        'name'   => 'findAll',
                    ),
                )
            ));

This continues to work anyway. That's why maybe, we should expect the annotations way to work too

@mpalourdio
Copy link
Contributor Author

It seems that other few things seem broken to me. Maybe I don't use them correctly. But simply the following doesn't seem to generate a radio element. Just generates an input text

 /**
     * @ORM\Column(type="string")
     * @Annotation\Options({"label":"Choices", "value_options":{"f":"nope","t":"okay"}})
     * @Annotation\Type("radio")
     */
    protected $choice;

I know that 't and 'f' aren't really booleans, but I work on an existing database

@mpalourdio
Copy link
Contributor Author

Hmm, seems in a certain way related to #242. Will give it another try tonight and see if there's an easy workaround with the listener.

@mpalourdio
Copy link
Contributor Author

okay, provided quick fixes, but not really sure they are in a fashion way :/ Before I improve or submit a PR, here are 2 gists that fix the problems. All comments welcome. Be indulgent :]

https://gist.github.com/mpalourdio/6736088 (is it possible to get the sl in any way to retrieve the config, and then the aliases of the form elements ? Would be better thant hard-code them)
https://gist.github.com/mpalourdio/6736091#file-elementannotationslistener-php-L238-L254

@mpalourdio
Copy link
Contributor Author

handled by #272

@Ocramius Ocramius added the bug label Feb 6, 2014
@Ocramius Ocramius added this to the 0.9.0 milestone Feb 6, 2014
@Ocramius Ocramius self-assigned this Feb 6, 2014
Ocramius added a commit that referenced this issue Feb 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants