EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Add CRUD form option for to-one associations

Open michaelKaefer opened this issue 3 years ago • 2 comments

Without this PR the association field renders a a dropdown and you cannot edit the associated entity but just select an already existing entity. If you want to edit an associated entity you cannot use AssociationField and so you have to create a custom EA field. Creating a custom EA field doesn't allow using EA fields and could sometimes kind of duplicate the CRUD form of the associated entity. This PR would enable you to use the CRUD form for AssociationField if it is a to-one association (for to-many associations CollectionField can be used).

I createad a reproducer: https://github.com/michaelKaefer/ea-reproducer/tree/association-field-use-crud-form.

Similar to https://github.com/EasyCorp/EasyAdminBundle/pull/5210.

michaelKaefer avatar Aug 05 '22 14:08 michaelKaefer

@devzenfr Thank you for finding and fixing this errors! I think the PR is finished now.

michaelKaefer avatar Aug 14 '22 08:08 michaelKaefer

@devzenfr Thank you for finding and fixing this errors! I think the PR is finished now.

Can confirm that it looks great. I'm now using a fork including your PR and everything is working smoothly. Nice job 🙏

devzenfr avatar Aug 14 '22 09:08 devzenfr

hey @michaelKaefer , thank you for your work . is this PR going to be merged soon ?

ahmedyakoubi avatar Nov 02 '22 18:11 ahmedyakoubi

Hi @ahmedyakoubi , no sorry, I don't know if and when it gets merged.

michaelKaefer avatar Nov 03 '22 10:11 michaelKaefer

I apologize to @michaelKaefer for not having merged this on time. I'm going to try to merge it soon.

javiereguiluz avatar Nov 03 '22 19:11 javiereguiluz

thank you @javiereguiluz and @michaelKaefer .

ahmedyakoubi avatar Nov 03 '22 20:11 ahmedyakoubi

This is finally merged 🙏

Michael, thanks a lot for this contribution. Your code was very easy to follow and implemented the feature in a nice and concise way. I also thank you for the reproducer (https://github.com/michaelKaefer/ea-reproducer/tree/association-field-use-crud-form) because it allowed me to play with the feature very easily.

While merging I did some tweaks. First, I reworded the docs a bit because I had some troubles while trying to fully understand the purpose of the feature. If I did some mistakes, we can fix it in a follow-up PR.

Second, I renamed the option to renderAsEmbeddedForm() (instead of the original useCrudForm()). As any naming, everything is debatable, but I felt that the original name was a bit generic and the new one is a bit more clear, although is longer. As always, if folks think that the new name is worse, we can revert the change.

Here are the tweaks: https://github.com/EasyCorp/EasyAdminBundle/commit/ae79fa8912c6ad4941f26efd1f7603ec97c5db79

javiereguiluz avatar Nov 05 '22 18:11 javiereguiluz

Thank you, the docs are a lot better now, good to understand!

michaelKaefer avatar Nov 08 '22 08:11 michaelKaefer