Sonata Admin Bundle - 添加多步骤批处理操作 [英] Sonata Admin Bundle - add a multi step batch action

查看:23
本文介绍了Sonata Admin Bundle - 添加多步骤批处理操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向我的 SonataAdmin 实体添加一个自定义批处理操作,允许用户在列表视图中选择多个项目,然后选择自定义批处理操作(称为编辑日期")然后...我被卡住了...显示一个包含两个日期字段的表单,当提交时,使用输入的日期更新所选列表项.

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.

是否有可能在 SonataAdminBundle 中进行这样的多步骤批处理操作?

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 %}

来源:13.2.(可选)覆盖批量选择模板

这会将您的字段添加到每一行.

This will add your fields to each row.

如果您只需要一次字段,例如在页脚中(靠近批处理操作选择和导出功能),您可以覆盖 CRUD/base_list.html.twig 管理类中的模板:

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;
    }
}

然后使用 batchActionMultiStep() 方法中的值.

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

这篇关于Sonata Admin Bundle - 添加多步骤批处理操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆