templates/bundles/EasyAdminBundle/default/list.html.twig line 1

Open in your IDE?
  1. {% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %}
  2. {% trans_default_domain _entity_config.translation_domain %}
  3. {% set _trans_parameters = { '%entity_name%': _entity_config.name|trans, '%entity_label%': _entity_config.label|trans } %}
  4. {% extends '@!EasyAdmin/default/list.html.twig' %}
  5. {% set _request_parameters = app.request.query.all|merge(_request_parameters|default({}))|merge({
  6.     action: app.request.get('action'),
  7.     entity: _entity_config.name,
  8.     menuIndex: app.request.get('menuIndex'),
  9.     submenuIndex: app.request.get('submenuIndex'),
  10.     sortField: app.request.get('sortField'),
  11.     sortDirection: app.request.get('sortDirection'),
  12.     page: app.request.get('page', 1),
  13.     filters: app.request.get('filters', []),
  14.     referer: null
  15. }) %}
  16. {% if 'search' == app.request.get('action') %}
  17.     {% set _request_parameters = _request_parameters|merge({
  18.         query: app.request.get('query')|default(''),
  19.     }) %}
  20. {% endif %}
  21. {% set _request_parameters = _request_parameters|merge({ referer: path('easyadmin', _request_parameters)|url_encode }) %}
  22. {% set _has_batch_actions = batch_form is defined and batch_form.vars.batch_actions|length > 0 %}
  23. {% set _has_filters = _entity_config.list.filters|default(false) %}
  24. {% block global_actions %}
  25.     {% if easyadmin_action_is_enabled_for_list_view('new', _entity_config.name) %}
  26.         {% set _action = easyadmin_get_action_for_list_view('new', _entity_config.name) %}
  27.         {% block new_action %}
  28.             <a class="{{ _action.css_class|default('') }}" href="{{ path('easyadmin', _request_parameters|merge({ action: _action.name })) }}" target="{{ _action.target }}">
  29.                 {% if _action.icon %}<i class="fa fa-fw fa-{{ _action.icon }}"></i>{% endif %}
  30.                 {{ _action.label is defined and not _action.label is empty ? _action.label|trans(_trans_parameters) }}
  31.             </a>
  32.         {% endblock new_action %}
  33.     {% endif %}
  34. {% endblock global_actions %}
  35. {% block batch_actions %}
  36. {% endblock batch_actions %}
  37. {% block content_breadcrumb_link %}
  38.     {% set _default_title = 'list.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %}
  39.     <li class="active"> {{ (_entity_config.list.title is defined ? _entity_config.list.title|trans(_trans_parameters) : _default_title)|raw }} </li>
  40. {% endblock content_breadcrumb_link %}
  41. {% block content_header_title %}
  42.     <i class="fa fa-{{ _entity_config.icon is defined ? _entity_config.icon : "cog" }}"></i>
  43.     {% apply spaceless %}
  44.     {% set _default_title = 'list.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %}
  45.     {{ (_entity_config.list.title is defined ? _entity_config.list.title|trans(_trans_parameters) : _default_title)|raw }}
  46.     {% endapply %}
  47. {% endblock %}
  48. {% block main %}
  49.     {% set _fields_visible_by_user = fields|filter((metadata, field) => easyadmin_is_granted(metadata.permission)) %}
  50.     {% set _number_of_hidden_results = 0 %}
  51.     {% set _list_item_actions = easyadmin_get_actions_for_list_item(_entity_config.name) %}
  52.     <div class="panel">
  53.         <div class="panel-heading">
  54.             <div class="panel-control">
  55.                 {{- block('global_actions') -}}
  56.             </div>
  57.             {% if _has_batch_actions %}
  58.                 <div class="batch-actions" style="display: none; padding: 10px 15px; float: right;">
  59.                     {% form_theme batch_form with easyadmin_config('design.form_theme') only %}
  60.                     {{ form(batch_form) }}
  61.                     {{ include('@EasyAdmin/default/includes/_batch_action_modal.html.twig', {
  62.                         _translation_domain: _entity_config.translation_domain,
  63.                         _trans_parameters: _trans_parameters,
  64.                         _entity_config: _entity_config,
  65.                     }, with_context = false) }}
  66.                 </div>
  67.             {% endif %}
  68.             <h3 class="panel-title">{{- block('content_title') -}}</h3>
  69.             <div class="toast">&nbsp;</div>
  70.         </div>
  71.         <div class="panel-body">
  72.             <div class="row">
  73.                 <div class="col-12 form-inline justify-content-end" style="margin-bottom: 15px;">
  74.                     {% if easyadmin_action_is_enabled_for_list_view('search', _entity_config.name) %}
  75.                         {% set _action = easyadmin_get_action_for_list_view('search', _entity_config.name) %}
  76.                         {% block search_action %}
  77.                             <div class="form-action form-action-search {{ _action.css_class|default('') }}" style="margin-right: 10px;">
  78.                                 <form method="get" action="{{ path('easyadmin') }}">
  79.                                     {% block search_form %}
  80.                                         <input type="hidden" name="action" value="search">
  81.                                         <input type="hidden" name="entity" value="{{ _request_parameters.entity }}">
  82.                                         {# if the Request query doesn't define 'sortField' and 'sortDirection', we add them in the
  83.                                            controller (but they don't appear in the request URI). When users click on a column to
  84.                                            sort results, 'sortField' and 'sortDirection' are added to the Request query and they
  85.                                             appear in the request URI too. So, checking if 'sortField' and 'sortDirection' is the
  86.                                             only way to differentiate between sorting made by user and sorting made by us. We only
  87.                                             need to persist the sorting if it's explicitly made by the user. #}
  88.                                         {% if 'sortField' in app.request.uri %}
  89.                                             <input type="hidden" name="sortField" value="{{ _request_parameters.sortField }}">
  90.                                         {% endif %}
  91.                                         {% if 'sortDirection' in app.request.uri %}
  92.                                             <input type="hidden" name="sortDirection" value="{{ _request_parameters.sortDirection }}">
  93.                                         {% endif %}
  94.                                         <input type="hidden" name="menuIndex" value="{{ _request_parameters.menuIndex }}">
  95.                                         <input type="hidden" name="submenuIndex" value="{{ _request_parameters.submenuIndex }}">
  96.                                         {% for name, value in _request_parameters.filters|easyadmin_form_hidden_params('filters') %}
  97.                                             <input type="hidden" name="{{ name }}" value="{{ value }}">
  98.                                         {% endfor %}
  99.                                         <div class="form-group">
  100.                                             <div class="form-widget">
  101.                                                 <input class="form-control" type="search" name="query" value="{{ app.request.get('query')|default('') }}" placeholder="{{ _action.label|default('action.search')|trans(_trans_parameters) }}">
  102.                                             </div>
  103.                                         </div>
  104.                                     {% endblock %}
  105.                                 </form>
  106.                             </div>
  107.                         {% endblock search_action %}
  108.                     {% endif %}
  109.                     {% if _has_filters %}
  110.                         {% set _applied_filters = app.request.attributes.get('easyadmin').filters.applied|default(false) %}
  111.                         {% block filters_action %}
  112.                             <div class="btn-group action-filters">
  113.                                 <a href="{{ path('easyadmin', _request_parameters|merge({ action: 'filters', referer_action: app.request.get('action') })) }}" class="btn btn-secondary btn-labeled-right action-filters-button {{ _applied_filters ? 'action-filters-applied' }}" data-modal="#modal-filters">
  114.                                     <i class="fa fa-filter fa-fw"></i> {{ 'filter.title'|trans(_trans_parameters, 'EasyAdminBundle') }}{% if _applied_filters %} <span class="text-primary">({{ _applied_filters|length }})</span>{% endif %}
  115.                                 </a>
  116.                                 {% if _applied_filters %}
  117.                                     <a href="{{ path('easyadmin', _request_parameters|merge({ filters: null })) }}" class="btn btn-secondary action-filters-reset">
  118.                                         <i class="fa fa-close"></i>
  119.                                     </a>
  120.                                 {% endif %}
  121.                             </div>
  122.                         {% endblock filters_action %}
  123.                     {% endif %}
  124.                 </div>
  125.             </div>
  126.             <table class="table table-striped table-bordered datagrid">
  127.                 <thead>
  128.                 {% block table_head %}
  129.                     <tr>
  130.                         {% if _has_batch_actions %}
  131.                             <th width="1px"><span><input type="checkbox" class="form-batch-checkbox-all"></span></th>
  132.                         {% endif %}
  133.                         {% for field, metadata in _fields_visible_by_user %}
  134.                             {% set isSortingField = (metadata.property == app.request.get('sortField')) or ('association' == metadata.type and app.request.get('sortField') starts with metadata.property ~ '.') %}
  135.                             {% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'DESC' %}
  136.                             {% set _column_label = metadata.label|trans(_trans_parameters) %}
  137.                             {% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
  138.                             <th class="{{ isSortingField ? 'sorted' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
  139.                                 {% if metadata.sortable %}
  140.                                     <a href="{{ path('easyadmin', _request_parameters|merge({ page: 1, sortField: metadata.property, sortDirection: nextSortDirection })) }}">
  141.                                         {{ _column_label|raw }} <i class="fa fa-fw {{ _column_icon }}"></i>
  142.                                     </a>
  143.                                 {% else %}
  144.                                     <span>{{ _column_label|raw }}</span>
  145.                                 {% endif %}
  146.                             </th>
  147.                         {% endfor %}
  148.                         {% if _list_item_actions|length > 0 %}
  149.                             <th {% if _entity_config.list.collapse_actions %}width="10px"{% endif %} {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
  150.                                 <span class="sr-only">{{ 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') }}</span>
  151.                             </th>
  152.                         {% endif %}
  153.                     </tr>
  154.                 {% endblock table_head %}
  155.                 </thead>
  156.                 <tbody>
  157.                 {% block table_body %}
  158.                     {% for item in paginator.currentPageResults %}
  159.                         {% if not easyadmin_is_granted(_entity_config.list.item_permission, item) %}
  160.                             {% set _number_of_hidden_results = _number_of_hidden_results + 1 %}
  161.                         {% else %}
  162.                             {# the empty string concatenation is needed when the primary key is an object (e.g. an Uuid object) #}
  163.                             {% set _item_id = '' ~ attribute(item, _entity_config.primary_key_field_name) %}
  164.                             <tr data-id="{{ _item_id }}">
  165.                                 {% if _has_batch_actions %}
  166.                                     <td><input type="checkbox" class="form-batch-checkbox" value="{{ _item_id }}"></td>
  167.                                 {% endif %}
  168.                                 {% for field, metadata in _fields_visible_by_user %}
  169.                                     {% set isSortingField = metadata.property == app.request.get('sortField') %}
  170.                                     {% set _column_label =  (metadata.label ?: field|humanize)|trans(_trans_parameters)  %}
  171.                                     <td class="{{ isSortingField ? 'sorted' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
  172.                                         {{ easyadmin_render_field_for_list_view(_entity_config.name, item, metadata) }}
  173.                                     </td>
  174.                                 {% endfor %}
  175.                                 {% if _list_item_actions|length > 0 %}
  176.                                     {% set _column_label =  'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') %}
  177.                                     <td class="actions">
  178.                                         {% block item_actions %}
  179.                                             {% set _actions_template = _entity_config.list.collapse_actions
  180.                                             ? '@EasyAdmin/default/includes/_actions_dropdown.html.twig'
  181.                                             : '@EasyAdmin/default/includes/_actions.html.twig'
  182.                                             %}
  183.                                             {{ include(_actions_template, {
  184.                                                 actions: _list_item_actions,
  185.                                                 entity_config: _entity_config,
  186.                                                 request_parameters: _request_parameters,
  187.                                                 translation_domain: _entity_config.translation_domain,
  188.                                                 trans_parameters: _trans_parameters,
  189.                                                 item_id: _item_id,
  190.                                                 item: item
  191.                                             }, with_context = false) }}
  192.                                         {% endblock item_actions %}
  193.                                     </td>
  194.                                 {% endif %}
  195.                             </tr>
  196.                         {% endif %}
  197.                     {% else %}
  198.                         <tr>
  199.                             <td class="no-results" colspan="{{ _fields_visible_by_user|length + 1 }}">
  200.                                 {{ 'search.no_results'|trans(_trans_parameters, 'EasyAdminBundle') }}
  201.                             </td>
  202.                         </tr>
  203.                     {% endfor %}
  204.                     {% if _number_of_hidden_results > 0 %}
  205.                         <tr class="datagrid-row-empty">
  206.                             <td class="text-center" colspan="{{ _fields_visible_by_user|length + 1 }}">
  207.                                 <span class="datagrid-row-empty-message"><i class="fa fa-lock mr-1"></i> {{ 'security.list.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  208.                             </td>
  209.                         </tr>
  210.                     {% endif %}
  211.                 {% endblock table_body %}
  212.                 </tbody>
  213.             </table>
  214.         </div>
  215.         <div class="panel-footer">
  216.             {{ include(_entity_config.templates.paginator) }}
  217.         </div>
  218.     </div>
  219.     {% block delete_form %}
  220.         {% set referer = paginator.currentPage == paginator.nbPages and 1 != paginator.currentPage and 1 == paginator.currentPageResults|length
  221.             ? path('easyadmin', app.request.query|merge({ page: app.request.query.get('page') - 1 }))
  222.             : app.request.requestUri
  223.         %}
  224.         {{ include('@EasyAdmin/default/includes/_delete_form.html.twig', {
  225.             view: 'list',
  226.             referer: referer,
  227.             delete_form: delete_form_template,
  228.             _translation_domain: _entity_config.translation_domain,
  229.             _trans_parameters: _trans_parameters,
  230.             _entity_config: _entity_config,
  231.         }, with_context = false) }}
  232.     {% endblock delete_form %}
  233. {% endblock main %}
  234. {% block content_footer_wrapper '' %}
  235. {% block body_javascript %}
  236.     {{ parent() }}
  237.     {{ include('@EasyAdmin/default/includes/_body_javascript.html.twig') }}
  238. {% endblock body_javascript %}