sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

New Batch Action for Mass Edit Form #7844

Closed Hanmac closed 2 years ago

Hanmac commented 2 years ago

Make a Batch Action that opens a Form similar to the Edit Form but the difference is that no values are set and each Input has a checkbox to enable the change. The Data in the Form will then be applied to all the entries that were selected in the list before.

an example would be to change the group for a list of customers into something else. or changing the tax class for a bunch of products.

I don't have an idea yet if it should be part of AbstactAdmin or if it should be coded as AdminExtension

VincentLanglet commented 2 years ago

I think this would be better to be done directly in each developper project because there will be always specific needs.

And for instance this will create issue with form validations. What if you want to set the value Foo to the entities A, B, C but your validations constraints doesn't allow the B one to be modified ?

Since everybody will want different behavior, it's better to let people create their own custom implementations. Creating his own batch actions is pretty easy with Sonata.

haivala commented 2 years ago

I would say this is something that documentation could explain and give people direction how to do it properly. Like should you use AdminExtension or how to do it.

VincentLanglet commented 2 years ago

There is already a complete doc about batch actions https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/batch_actions/

Hanmac commented 2 years ago

might need to wait till #7819 before i should try to make this into an extension if i want to try to make a generic Controller Function for this if able?

my idea was to make it as easy for the users as possible, so they just would have needed to add the form fields into an action. and the rest could have been handled by the base code. Like using a similar form mapper where the outer Form Fields and Form templates are handled by the Extension.

And for instance this will create issue with form validations. What if you want to set the value Foo to the entities A, B, C but your validations constraints doesn't allow the B one to be modified ?

for this i can see different results which could be configurable.

VincentLanglet commented 2 years ago

This was already proposed here: https://github.com/sonata-project/SonataAdminBundle/issues/4105, and this is a pretty good proof that the interest in favor of this feature was pretty low.

Everytime a new feature is proposed, we need to ask ourself some questions

WDYT about it @jordisala1991 ?

haivala commented 2 years ago

There is already a complete doc about batch actions https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/batch_actions/

Ah. I guess I missed something when I implemented one years ago.

Hanmac commented 2 years ago

i'm currently looking for a way/example to define multi-step batch Action

i would assume that for the first action i need to store the ids in a hidden form field, and have the form fields getting defined by the Admin (via an extra Interface) i problably can't use FormMapper to help me wrapping the form templates around my helper templates similar to Filter?

and a second batch action for saving the form field options

Edit: especially if i want to call by batch action from multiple different admins, would i need a Controller for each of them? or is the Admin variable set depending on where it is calling from?

mpoiriert commented 2 years ago

@Hanmac This is a feature that my client might be interested in. It's not a top priority but still.

I would recommend that a specific "form" must be defined for this.

Maybe create a interface that will be use on the Admin class itself. Use the same form mapper object use to configure form.

Your extension would check if the admin has this interface implemented configure everything necessary and will use the method of the interface to configure the form in the batch update controller.

Hanmac commented 2 years ago

That was my current plan so far:

the next thing i need to get done is that two steps thing, with the first part showing the form, and the second part applying the form data / validation on the entities. For this to test, i might use the Confirmation Form Template

VincentLanglet commented 2 years ago

I'm gonna close this, since it won't be implemented in this project. You can still discuss here or in a slack.