简体   繁体   中英

Sonata Admin Bundle - add a multi step batch action

I need to add a custom batch action to my SonataAdmin entity that allows the user to select a number of items in the list view, then select the custom batch action (called 'edit dates') then... and here's where I'm stuck... display a form with two date fields that, when submitted, updates the selected list items with the inputted dates.

Is it even possible to have a multi-step batch action like this in SonataAdminBundle?

You can add your date fields to the template:

{# in Acme/ProjectBundle/Resources/views/CRUD/list__batch.html.twig #}
{# See SonataAdminBundle:CRUD:list__batch.html.twig for the current default template #}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
    <input type="checkbox" name="idx[]" value="{{ admin.id(object) }}" />

    {# your date fields here #}
    <input type="date" name="start" />
    <input type="date" name="end" />
{% endblock %}

Source: 13.2. (Optional) Overriding the batch selection template

This will add your fields to each row.

If you only need the fields once eg in the footer (near the batch action select and export function) you can override the CRUD/base_list.html.twig template in your admin class:

public function getTemplate($name)
{
    switch ($name) {
        case 'list':
            return 'MyBundle:MyAdmin:list.html.twig';
            break;

        default:
            return parent::getTemplate($name);
            break;
    }
}

And then use the values inside your batchActionMultiStep() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM