People,
I was able to resolve the question:
1- How to add button on CRUD.
It´s required to copy twig from
vendor/sonata-project/admin-bundle/Resources/views/CRUD/base_edit_form.html.twig
to
app/Resources/SonataAdminBundle/views/CRUD. And it´s edit the following
part of de code int then {% block formations %}:
{% if admin.hasroute('<inform_name_route>') %}
<a class="btn btn-success" href="{{
admin.generateObjectUrl('<inform_name_route>', object) }}">View</a> {% endif
%}
2- This is route will call a controller. You must create it.
3- So that de button created becomes available a especific CRUD screen,
it´s required:
public function configureRoutes(RouteCollection $collection)
{
$collection->add('<inform_name_route>', '<inform_path_route>',
array(
'_controller' => '<inform_defaults_route>'
), array(
'<inform_required_parameter>' => '\d+'
));
}
Thanks,
Aline.
Em sexta-feira, 18 de novembro de 2016 14:11:37 UTC-2, Aline Macena
escreveu:
>
> Hi,
>
> I would like to add a button in screen of CRUD corresponding to edit. I am
> using the following:
>
> src/Acme/DemoBundle/Admin/EntityAdmin.php:
>
> protected function configureRoutes(\Sonata\AdminBundle\Route\RouteCollection
> $collection){
> $collection
> ->add('button_1',
> 'button_1/{id}',
> array('_controller' => 'AcmeDemoBundle:Default:button_1'),
> array('id' => '\d+')
> )
> ;}
>
> src/Acme/HelloBundle/Controller/DefaultController.php:
>
> /**
> @Route("/button_1/{id}", name="button_1",
> requirements={"id" = "\d+"}
> )
> @Template("AcmeDemoBundle:Default:button_1.html.twig")
> */public function button_1Action($id)
> {
> return(array(
> 'id' => $id
> ));}
>
> app/Resources/SonataAdminBundle/views/CRUD/base_edit_form.html.twig:
>
> {% block form %}
> ...
> {% else %}
> ...
> {% block formactions %}
> ...
> {% else %}
> ...
> {% if admin.id(object) %}
> ...
> {% if admin.hasroute('button_1') %}
> <a class="btn" target="_blank" href="{{
> admin.generateObjectUrl('button_1', object) }}">{% trans from
> 'SonataAdminBundle' %}link_button_1{% endtrans %}</a>
> {% endif %}
> ...
>
>
> But the button doesnt't appear and the controller doesn't called. What
> would be the correct way to do this action, please?
>
> Thanks,
> Aline.
>
--
You received this message because you are subscribed to the Google Groups
"sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.