henk-s
9/14/2016 - 6:16 PM

easyadmin customize action.list row

easyadmin customize action.list row

up vote
0
down vote
accepted
After several tweaking and failures, I have found a solution, it was documented but I did not expect it to be documented there nested.

Here's the github page: Advanced Design Configuration

We will overwrite the default html.twig file by overriding the {{ block }}

Create an Overwrite Folder

First, create a folder easy_admin inside Resources\views.

Suppose you want to change list.row_actions, head over to the source file from easy-admin usually inside:

vendor\javiereguiluz\easyadmin-bundle\views\default\includes\
Finding the source

Find the list.html.twig file and check out its content for a brief. If you CTRL + F (Find) for list.row_actions, it will show you directly something like this. Now copy the whole block

        {% block table_head %}
        <tr>
            {% for field, metadata in fields %}
                {% set isSortingField = metadata.property == app.request.get('sortField') %}
                {% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'DESC' %}
                {% set _column_label = (metadata.label ?: field|humanize)|trans(_trans_parameters) %}
                {% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-caret-up' : 'fa-caret-down') : 'fa-sort' %}

                <th data-property-name="{{ metadata.property }}" class="{{ isSortingField ? 'sorted' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}">
                    {% if metadata.sortable %}
                        <a href="{{ path('easyadmin', _request_parameters|merge({ sortField: metadata.property, sortDirection: nextSortDirection })) }}">
                            <i class="fa {{ _column_icon }}"></i>
                            {{ _column_label|raw }}
                        </a>
                    {% else %}
                        <span>{{ _column_label|raw }}</span>
                    {% endif %}
                </th>
            {% endfor %}

            {% if _list_item_actions|length > 0 %}
                <th>
                    <span>{{ 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') }}</span>
                </th>
            {% endif %}
        </tr>
    {% endblock table_head %}
Pasting to Overwrite File

To paste/overwrite this, you need to create a file with exact name as the filename where you copied it. In this case, list.html.twig. Then paste it inside the file

IMPORTANT : At top of the file, include this tag -

{% extends '@EasyAdmin/default/list.html.twig' %}

{% block table_head %}
<tr>
    {% for field, metadata in fields %}
    ...code continues...
Why overwrite?

If you edit the file from the source code, you will have trouble deploying it especially if you're using git clone and then composer update.

Overwriting make sure that the code persist even when you deploy it.