Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set correct classes and disabled states for the _pager_basic.html.twig pager #2460

Merged
merged 6 commits into from
Mar 13, 2021
Merged
16 changes: 6 additions & 10 deletions templates/helpers/_pager_basic.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ Predefined variables:

{% block item %}
{% if path is defined %}
<li class="{{ class }}">
<a href="{{ path }}">{{ label|default('…') }}</a>
</li>
{% elseif enabled is defined and enabled == false %}
<li class="{{ class }}">
<a disabled>{{ label|default('…') }}</a>
<li {% if class|default %}class="{{ class }}"{% endif %} {% if enabled is defined and not enabled %}disabled="disabled"{% endif %}>
<a {% if 'active' in class|default %}aria-current="page"{% endif%} {% if enabled is defined and not enabled %}disabled="disabled"{% else %}href="{{ path }}"{% endif %}>{{ label|default('…') }}</a>
</li>
{% endif %}
{% endblock item %}
Expand All @@ -29,7 +25,7 @@ Predefined variables:

{# Previous Button #}
{% set p = routeParams|merge({page: records.hasPreviousPage ? records.previousPage : 1 }) %}
{% with {'path': path(route, p), 'label': 'pager.previous'|trans, 'enabled': records.hasPreviousPage } %}
{% with {'path': path(route, p), 'label': 'pager.previous'|trans, 'enabled': records.hasPreviousPage } only %}
{{ block('item') }}
{% endwith %}

Expand All @@ -39,7 +35,7 @@ Predefined variables:
{% with {'path': path(route, p), 'label': 1 } %}
{{ block('item') }}
{% endwith %}
{% with { 'label': '…', 'enabled': false } %}
{% with { 'label': '…', 'enabled': false } %}
{{ block('item') }}
{% endwith %}
{% endif %}
Expand All @@ -48,7 +44,7 @@ Predefined variables:
{% for i in start .. end %}
{% set p = routeParams|merge({page: i}) %}
{% set class = (i == records.currentPage ? ' active' : '') %}
{% with {'path': path(route, p), 'label': i, 'class': class } %}
{% with {'path': path(route, p), 'label': i, 'class': class, 'enabled': true } %}
{{ block('item') }}
{% endwith %}
{% endfor %}
Expand All @@ -65,7 +61,7 @@ Predefined variables:
{% endif %}

{% set p = routeParams|merge({page: records.hasNextPage ? records.nextPage : records.nbPages }) %}
{% with {'path': path(route, p), 'label': 'pager.next'|trans, 'enabled': records.hasNextPage } %}
{% with {'path': path(route, p), 'label': 'pager.next'|trans, 'enabled': records.hasNextPage } only %}
{{ block('item') }}
{% endwith %}
</ul>
Expand Down