Skip to content

Allow custom Symfony Form integration for batch actions #7582

@tugrul

Description

@tugrul

Short description of what this feature will allow to do:

Currently, batch actions in EasyAdmin are limited to simple triggers without the ability to attach a fully customizable Symfony Form. This feature would allow developers to define and use a custom FormType for batch actions, enabling additional user input, validation, and structured data handling before processing the selected entities. This would make batch actions significantly more flexible and suitable for more complex workflows.

Example of how to use this feature

// src/Controller/Admin/ProductCrudController.php

use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use App\Form\BatchUpdateType;

public function configureActions(Actions $actions): Actions
{
    return $actions->addBatchAction(
        Action::new('batchUpdate', 'Update Products')
            ->useForm(BatchUpdateType::class) // proposed API
            ->linkToCrudAction('handleBatchUpdate')
    );
}

public function handleBatchUpdate(BatchActionDto $dto, Request $request): Response
{
    $form = $dto->getForm(); // proposed access to submitted form

    if ($form->isSubmitted() && $form->isValid()) {
        $data = $form->getData();
        $entityIds = $dto->getEntityIds();

        // apply updates using both selected entities and form data
    }

    return $this->render('admin/batch_update.html.twig', [
        'form' => $form->createView(),
    ]);
}
// src/Form/BatchUpdateType.php

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class BatchUpdateType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('status', ChoiceType::class, [
            'choices' => [
                'Draft' => 'draft',
                'Published' => 'published',
            ],
        ]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions