Search code examples
phpsymfonysymfony4easyadmin

Symfony 4 easy admin how to create common action?


How to create common action like 'new' which will be do one action, for example send ajax request for get some kind of information. I'm trying add action via config/packages/easy_admin.yaml

easy_admin:
  entities:
    Users:    
      list:
        actions:
          - { name: 'refresh', label: 'Refresh', icon: 'sync' }

But it's add 'refresh' link for each row in my list.

I will be grateful for example or link on information.


Solution

  • That's not supported natively for now.

    https://github.com/EasyCorp/EasyAdminBundle/issues/1400

    You have to override the default list template to add your custom buttons:

    {# /templates/bundles/EasyAdminBundle/default/list.html.twig #}
    
    {% extends '@!EasyAdmin/default/list.html.twig' %}
    
    {% block global_actions %}
        {{ parent() }}
    
        {# Add your code here, for example a button on the 'Users' list #}
        {% if _entity_config.name == "Users" %}
            <div class="button-action">
                <a class="btn btn-primary" href="#">Refresh</a>
            </div>
        {% endif %}
    {% endblock %}