Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Crudit Bundle Laravel Package

2lenet/crudit-bundle

Symfony bundle to rapidly build configurable CRUD back offices with SB Admin layout. Provides list views with pagination, sorting, actions, exports and batch ops, plus datasources, filters, menus, workflows, maps, markdown and Twig helpers.

View on GitHub
Deep Wiki
Context7

How to add batch actions in your list

The batch actions allow to perform a given action on the pre-selected items of the list.

In your src/Crudit/Config/EntityCrudConfig.php, you have to overload the getListActions() method of the AbstractCrudConfig. Inside your getListActions() method, you can add a new action and add ->setIsBatch() to it:

    public function getListActions(): array
    {
        $actions =  parent::getListActions();
        
        $actions[] = ListAction::new(
                'action.batch.exporter',
                Path::new('exporter_intervention'),
                Icon::new('file-export')
            )->setIsBatch();
            
        return $actions;           
    }

Then, in your src/Controller/Crudit/EntityContoller.php you can write the method that the batch action is going to execute:

    /**
     * [@Route](https://github.com/Route)("/exporter_intervention", name="exporter_intervention")
     */
    public function exporterInterventions(Request $request, ResourceResolver $resolver, Exporter $exporter)
    {
        if ((bool)$request->query->get('all_page')) {
            // get data from datasource
            
            ...
        } else {
            $ids = explode(",", $request->get("ids"));
            
            ...
        }
        
        ...
    }

This will result in:

That's it!

How to add a form to the batch action

After ->setIsBatch() you need to add ->setForm() and pass as parameter your form like this :

    public function getListActions(): array
    {
        $actions =  parent::getListActions();
        
        $actions[] = ListAction::new(
                'action.batch.exporter',
                Path::new('exporter_intervention'),
                Icon::new('file-export')
            )->setIsBatch()->setForm(YourFormType::class);
            
        return $actions;           
    }

In your form you can add all the fields you need, but just 1 is required :

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        // All the fields you need
        $builder->add('intervention');

        // The required fields
        $builder->add('ids', HiddenType::class, [
            'label' => false
        ]);
        $builder->add('all_page', HiddenType::class, [
            'label' => false
        ]);
    }

Now in your controller you can find all the selected ids and the different values of your form like this :

    /**
     * [@Route](https://github.com/Route)("/exporter_intervention", name="exporter_intervention")
     */
    public function exporterInterventions(Request $request, ResourceResolver $resolver, Exporter $exporter)
    {
        /** [@var](https://github.com/var) array $params */
        $params = $request->request->get('exporter_intervention');

        $intervention = $params['intervention'];
        if ((bool)$params['all_page']) {
            // get data from datasource
            
            ...
        } else {
            $ids = explode(',', $params['ids']);
            
            ...
        }
        
        ...
    }
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
bugban/php-sdk
littlerocket/job-queue-bundle
graham-campbell/flysystem
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/opensearch-client
directorytree/opensearch-adapter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php