添加自定义按钮以编辑奏鸣曲管理包的页面 [英] Add custom button to edit page of sonata admin bundle

查看:23
本文介绍了添加自定义按钮以编辑奏鸣曲管理包的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,奏鸣曲管理包在编辑页面带有三个按钮,分别是添加新的、更新的和删除的".我可以用这个删除删除按钮:

As you know, sonata admin bundle comes with three buttons in edit page which are "Add new, update and delete". I can remove delete button with this:

protected function configureRoutes(RouteCollection $collection)
{
    $collection
        ->remove('delete')
    ;

}

但我还想在 UserAdmin 的编辑中添加向用户发送消息"按钮.我怎样才能做到这一点?我在奏鸣曲文档中找不到任何相关文档.

But I want to also add "Send message to User" button in edit of UserAdmin. How can I do this? I can't find any documentation about that in sonata docs.

推荐答案

如果文件在其他命名空间中,您应该提示参数,并且 add() 方法应该可以工作,但是您必须覆盖 Sonata 的 CRUD 模板以能够显示其他按钮/链接.
此外,您可以定义将被调用的控制器和动作.

You should hint the parameter if the file is in other namespace, and the add() method should work, but then you have to overwrite the Sonata's CRUD template to be able to display an other button/link.
Additionally you can define the controller and action which will be called.

例如:
src/Acme/DemoBundle/Admin/EntityAdmin.php:

For example:
src/Acme/DemoBundle/Admin/EntityAdmin.php:

protected function configureRoutes(\Sonata\AdminBundle\Route\RouteCollection $collection)
{
    $collection
        ->add('dummy',
            'dummy/{id}',
            array('_controller' => 'AcmeDemoBundle:Default:dummy'),
            array('id' => '\d+')
        )
    ;
}

src/Acme/HelloBundle/Controller/DefaultController.php:

src/Acme/HelloBundle/Controller/DefaultController.php:

/**
    @Route("/dummy/{id}", name="dummy",
        requirements={"id" = "\d+"}
    )
    @Template("AcmeDemoBundle:Default:dummy.html.twig")
*/
public function dummyAction($id)
{
    return(array(
        'id' => $id
    ));
}

app/Resources/SonataAdminBundle/views/CRUD/base_edit_form.html.twig:

app/Resources/SonataAdminBundle/views/CRUD/base_edit_form.html.twig:

{% block form %}
    ...
    {% else %}
        ...
        {% block formactions %}
            ...
            {% else %}
                ...
                {% if admin.id(object) %}
                    ...
                    {% if admin.hasroute('dummy') %}
                        <a class="btn" target="_blank" href="{{ admin.generateObjectUrl('dummy', object) }}">{% trans from 'SonataAdminBundle' %}link_dummy{% endtrans %}</a>
                    {% endif %}
                    ...

这篇关于添加自定义按钮以编辑奏鸣曲管理包的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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