简体   繁体   English

添加自定义按钮以编辑奏鸣曲管理包的页面

[英]Add custom button to edit page of sonata admin bundle

As you know, sonata admin bundle comes with three buttons in edit page which are "Add new, update and delete". 如您所知,sonata admin捆绑包在编辑页面中有三个按钮,分别是“添加新的,更新和删除”。 I can remove delete button with this: 我可以删除删除按钮:

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

}

But I want to also add "Send message to User" button in edit of UserAdmin. 但我想在编辑UserAdmin时添加“向用户发送消息”按钮。 How can I do this? 我怎样才能做到这一点? I can't find any documentation about that in sonata docs. 我在sonata docs中找不到任何关于它的文档。

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. 如果文件在其他命名空间中,您应该提示参数,并且add()方法应该可以工作,但是您必须覆盖Sonata的CRUD模板才能显示其他按钮/链接。
Additionally you can define the controller and action which will be called. 此外,您可以定义将被调用的控制器和操作。

For example: 例如:
src/Acme/DemoBundle/Admin/EntityAdmin.php: SRC /阿克米/ DemoBundle /管理/ 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 /控制器/ 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: 应用程序/资源/ SonataAdminBundle /视图/ 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 %}
                    ...

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

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