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

Made the Annotation builder automatically pass the EntityManager to Form Elements which need it. #180

Closed
wants to merge 2 commits into from

Conversation

tomphp
Copy link

@tomphp tomphp commented Feb 19, 2013

Currently the only way I have found to get my

\DoctrineORMModule\Form\Element\EntitySelect

elements to populate is, after creating the form using the AnnotationBuilder, calling

$form->get('element_name')->setOptions(array('object_manager', $entityManager);

I find this pretty messy so this little mod does it automatically.

Hope you like it.

@Ocramius
Copy link
Member

@tomphp I do like the idea, but such stuff needs tests :\

Ping @bakura10


$elementSpec = $e->getParam('elementSpec');

$elementSpec['spec']['options']['object_manager'] = $this->em;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No side effects?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None that I'm aware of?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what I mean: what does this line do? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line which makes it all work. In order for EntityMultiCheckbox, EntityRadio & EntitySelect to work they required access to the EntityManager so they can fetch the options from the database, this is provided by an option called object_manager (see \DoctrineModule\Form\Element\Proxy). Here I am setting that option.

It saves having to call

$form->get('element_name')->setOptions(array('object_manager', $entityManager);

after the form has been created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$elementSpec is not retrieved byref as far as I know

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably when not using Annotation you would do something like

$form->add(array(
    'name' => 'entity_name',
    'type' => 'DoctrineORMModule\Form\Element\EntitySelect',
    'options' => array(
            'object_manager' => $entityManager,
    )
));

However when using Annotations to build a form you cannot set object_manager to an instance in the annotation. So here I'm getting the AnnotationBuilder to do it for these types of Element.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius I did wander about that but it seems to be working fine. Even though $elementSpec may not be retrieved by ref unless the value in object_manager is cloned it will still be a ref to the same object (since its an object and not a scalar) so it should be safe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, $elementSpec is an object?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was talking about the EntityManager object however $elementSpec is indeed an instance of ArrayObject ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh by the way if you're worried about assigning to $elementSpec then take look at the other handler methods in this class you'll see that several of the assign to $elementSpec is the same way ;-)

@tomphp
Copy link
Author

tomphp commented Feb 19, 2013

as in you want me to write some unit tests or as in the idea/method needs testing?

@Ocramius
Copy link
Member

I stopped merging PRs without tests :P

@tomphp
Copy link
Author

tomphp commented Feb 19, 2013

No problem, I did look at the tests there and so much was uncovered so I wasn't sure if I should do it or not. Will get on to it now...back in 10mins or so ;)

@bakura10
Copy link
Member

Speaking about it, I suppose most of the AnnotationBuilder could be moved to DotrineModule.

@tomphp
Copy link
Author

tomphp commented Feb 20, 2013

Where are we at with this? Is it still the question of $elementSpec which is the sticking point or is there anything else I need to do?

@tomphp
Copy link
Author

tomphp commented Mar 1, 2013

Is there anything I need to do with this to get it accepted or is the concept still in question?

@Ocramius
Copy link
Member

@tomphp can you cross-check #193?

@tomphp
Copy link
Author

tomphp commented Mar 28, 2013

@Ocramius by the looks of it #193 does what this was supposed to do (and more) so this should probably be closed?

@Ocramius
Copy link
Member

@tomphp I can merge your test into #193, that one is OK IMO.

Consider that the feature (regardless if this one or the one in #193) lands in 0.8

@tomphp
Copy link
Author

tomphp commented Mar 29, 2013

@Ocramius are you talking about DoctrineORMModuleTest/Form/ElementAnnotationsListenerTest?

If so all I really added to that was a test for the extra method I created so I don't think it's relevant to #193

Unless I'm misunderstanding or missing something?

@Ocramius
Copy link
Member

@tomphp nvm, I saw what you mean. I think it's just going to be funny to handle the merge conflicts, but that's up to me :)

@Ocramius
Copy link
Member

Scheduled for 0.8

@tomphp
Copy link
Author

tomphp commented Mar 29, 2013

@Ocramius do you think this PR is needed? To me it looks like lines 88 and 112 of `src/DoctrineORMModule/Form/Annotation/ElementAnnotationsListener.php' in #193 handle the functionality that I was aiming to provide with this PR. I think this PR is probable redundant?

Unless I'm missing something I think this PR should be closed and just #193 merged?

@Ocramius
Copy link
Member

@tomphp I will keep the test

@Ocramius
Copy link
Member

Sorry about the awfully late response :( I'm going to close this since the entire annotation listener was re-written to use metadata in #233

@Ocramius Ocramius closed this Jun 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants