-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Conversation
…orm Elements which need it.
|
||
$elementSpec = $e->getParam('elementSpec'); | ||
|
||
$elementSpec['spec']['options']['object_manager'] = $this->em; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No side effects?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
;)
There was a problem hiding this comment.
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 ;-)
as in you want me to write some unit tests or as in the idea/method needs testing? |
I stopped merging PRs without tests :P |
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 ;) |
Speaking about it, I suppose most of the AnnotationBuilder could be moved to DotrineModule. |
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? |
Is there anything I need to do with this to get it accepted or is the concept still in question? |
@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 :) |
Scheduled for 0.8 |
@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? |
@tomphp I will keep the test |
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 |
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.