-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use CRUD form in CollectionField #5210
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
Use CRUD form in CollectionField #5210
Conversation
914106c
to
0f787a5
Compare
1869712
to
c1a8336
Compare
c1a8336
to
24a99a1
Compare
Thanks, this looks great and seems it will solve many headaches I have. Would it be possible to either specify a crud form class name, or the name of a function in the crud form, so that a separate form could be utilised? e.g. it could be school -> pupils, with only basic values wanted in a collection field of pupils (name, date of birth), but full fields with tabs etc when editing pupil directly. |
@sxsws Sorry, I think it will not solve your headaches.. It seems that you want to maintain a collection of pupils in the form of another entity school. The problem is that your users cannot add existing pupils to the collection, even after this commit this is not possible. After this commit your users can only edit pupils which already are associated to the school, or they can add a new pupil. If this really is sufficient, then, ok, the headaches are solved :) What you are asking for is aleady possible in this PR: class SchoolCrudController extends AbstractCrudController
{
public function configureFields(string $pageName): iterable
{
return [
CollectionField::new('pupils')->useCrudForm(
true,
PupilCrudController::class,
'new_pupil_on_school_page',
'edit_pupil_on_school_page'
);
];
}
}
class PupilCrudController extends AbstractCrudController
{
public function configureFields(string $pageName): iterable
{
switch ($pageName) {
case 'new':
case 'edit':
return [TextField::new('foo'), TextField::new('bar'), TextField::new('baz')];
case 'new_pupil_on_school_page':
case 'edit_pupil_on_school_page':
return [TextField::new('foo')];
}
throw new \InvalidArgumentException();
}
} |
This is gold 🏆 - please merge! |
Since it needs SF6.1 this can be quite difficult to merge. @javiereguiluz want to preserve BC as much as possible. |
@parijke It only needs SF6.1 to work, with SF6.0 there is no problem at all, you just will get an exception if you want to still use the new feature. See https://github.com/EasyCorp/EasyAdminBundle/pull/5210/files#diff-100aaf7a11a06c600ef2c48bb42aa90c85ed6253721bf953770dbed7bdda8224 : // ...
throw new \RuntimeException('To enable CRUD form usage for collection fields Symfony 6.1 or higher is required.', 0, $exception); So AFAICS there is no problem to merge it. |
Nice! |
@javiereguiluz What do you think about this PR? If it doesn't get merged I would like to close it. Maybe it would help if I try to add tests? |
Michael, I'm sorry I haven't found the time to review this PR 🙏 I'll try to find time for it soon. Thanks! |
@javiereguiluz Ok, sorry, no need to hurry! |
This is great! I just switched to EasyAdmin and needed exactly this feature. Used your commit inside my project until this gets merged and this is working perfectly. Thanks for your work. |
@Lustmored @javiereguiluz Please look at this pull, we all need it. |
Michael, thanks for this feature and for the reproducer. I could play with the sample app that you provided and I liked it. I need a bit more time to think about the design of the feature and the naming of some methods, but I hope to merge this soon. Thanks! |
Thanks Michael! I'm merging this nice feature and I'll send a following PR with some minor tweaks. |
…on fields (javiereguiluz) This PR was merged into the 4.x branch. Discussion ---------- Minor tweaks in the feature to use CRUD forms in collection fields This PR proposes some minor tweaks in the #5210 feature contributed by `@michaelKaefer`. Commits ------- 19387e0 Minor tweaks in the feature to use CRUD forms in collection fields
Hello. Based on this future, how to display relation in Action::DETAIL? |
@allok You are working for a company in Minsk, I for sure will not answer your questions, because Belarus supports an illegal war. |
…efer) This PR was merged into the 4.x branch. Discussion ---------- Add CRUD form option for to-one associations 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 #5210. Commits ------- acd06da Add CRUD form option for to-one associations
Functionality introduced in EasyCorp#5353 (AssociationType) and in EasyCorp#5210 (CollectionType) rendered sub-CRUD controller with context of the primary CRUD controller. With invalid context, some functions, like default fields generation, aren't working properly. See EasyCorp#5512
Functionality introduced in EasyCorp#5353 (AssociationType) and in EasyCorp#5210 (CollectionType) rendered sub-CRUD controller with context of the primary CRUD controller. With invalid context, some functions, like default fields generation, aren't working properly. See EasyCorp#5512
Functionality introduced in EasyCorp#5353 (AssociationType) and in EasyCorp#5210 (CollectionType) rendered sub-CRUD controller with context of the primary CRUD controller. With invalid context, some functions, like default fields generation, aren't working properly. See EasyCorp#5512
Implements what @furang wrote here: #4766.
Needs Symfony 6.1 because it uses
prototype_options
(See symfony/symfony#45605).I createad a reproducer here: https://github.com/michaelKaefer/ea-reproducer/tree/issue/4766-create-update-relations.
Without this PR you have to create a form type and set it as entry type for associated entities when using
CollectionField
. This doesn't allow using EA fields and could sometimes kind of duplicates the CRUD form of the associated entity. This new option would enable you to use the CRUD form (if you need different form fields and you cannot reuse the CRUD form you still can implement a custom form type).Related to #3304.