我需要将一个自定义批处理操作添加到我的SonataAdmin实体中,该实体允许用户在列表视图中选择许多项,然后选择自定义批处理操作(称为“编辑日期”)。我被困在这里..。显示带有两个日期字段的窗体,在提交时,这些字段将使用输入的日期更新选定的列表项。
在SonataAdminBundle中甚至有可能有这样的多步骤批处理操作吗?
发布于 2014-08-22 10:57:54
可以将日期字段添加到模板中:
{# 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.(可选)覆盖批选择模板
这将将您的字段添加到每一行。
如果您只需要这些字段一次,例如在页脚(在批处理操作、选择和导出函数附近),您可以在管理类中覆盖list.html.twig模板:
public function getTemplate($name)
{
    switch ($name) {
        case 'list':
            return 'MyBundle:MyAdmin:list.html.twig';
            break;
        default:
            return parent::getTemplate($name);
            break;
    }
}然后使用batchActionMultiStep()方法中的值。
https://stackoverflow.com/questions/23996476
复制相似问题