Sonata Admin Bundle - add a multi step batch action

谁说我不能喝 提交于 2019-12-10 11:43:05

问题


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?


回答1:


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 e.g. 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.



来源:https://stackoverflow.com/questions/23996476/sonata-admin-bundle-add-a-multi-step-batch-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!