简体   繁体   English

Sonata Admin Bundle-添加多步骤批处理操作

[英]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. 我需要向我的SonataAdmin实体添加自定义批处理操作,该操作允许用户在列表视图中选择多个项目,然后选择自定义批处理操作(称为“编辑日期”),然后...在这里,卡住...显示带有两个日期字段的表单,提交后,这些表单将使用输入的日期更新所选列表项。

Is it even possible to have a multi-step batch action like this in SonataAdminBundle? 在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. 资料来源: 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: 如果只需要一次使用这些字段,例如在页脚中(在批处理操作选择和导出功能附近),则可以在管理类中覆盖CRUD / base_list.html.twig模板:

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. 然后在您的batchActionMultiStep()方法中使用值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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