Skip to content

Commit b7308c1

Browse files
authored
Page parameter name (#820)
1 parent 51c29fe commit b7308c1

12 files changed

+71
-64
lines changed

src/Helper/Processor.php

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function render(SlidingPaginationInterface $pagination, array $queryParam
3636

3737
$data['route'] = $pagination->getRoute();
3838
$data['query'] = \array_merge($pagination->getParams(), $queryParams);
39+
$data['options'] = $pagination->getPaginatorOptions();
3940

4041
return \array_merge(
4142
$pagination->getPaginatorOptions() ?? [], // options given to paginator when paginated

src/Twig/Extension/PaginationRuntime.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,26 @@ public function filter(
109109
}
110110

111111
/**
112-
* @param array<string, mixed> $query
113-
* @param int $page
112+
* @param array<string, mixed> $query
113+
* @param int $page
114+
* @param array<string, mixed> $options
114115
* @return array<string, mixed>
115116
*/
116-
public function getQueryParams(array $query, int $page): array
117+
public function getQueryParams(array $query, int $page, array $options): array
117118
{
119+
$pageName = $this->pageName;
120+
if (isset($options['pageParameterName']) && is_string($options['pageParameterName'])) {
121+
$pageName = $options['pageParameterName'];
122+
}
123+
118124
if ($page === 1 && $this->skipFirstPageLink) {
119-
if (isset($query[$this->pageName])) {
120-
unset($query[$this->pageName]);
125+
if (isset($query[$pageName])) {
126+
unset($query[$pageName]);
121127
}
122128

123129
return $query;
124130
}
125131

126-
return array_merge($query, [$this->pageName => $page]);
132+
return array_merge($query, [$pageName => $page]);
127133
}
128134
}

templates/Pagination/bulma_pagination.html.twig

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
{% if pageCount > 1 %}
1414
<nav class="{{ classes|join(' ') }}" role="navigation" aria-label="pagination">
1515
{% if previous is defined %}
16-
<a rel="prev" class="pagination-previous" href="{{ path(route, knp_pagination_query(query, previous)) }}">{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
16+
<a rel="prev" class="pagination-previous" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
1717
{% else %}
1818
<a class="pagination-previous" disabled>{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
1919
{% endif %}
2020

2121
{% if next is defined %}
22-
<a rel="next" class="pagination-next" href="{{ path(route, knp_pagination_query(query, next)) }}">{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}</a>
22+
<a rel="next" class="pagination-next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}</a>
2323
{% else %}
2424
<a class="pagination-next" disabled>{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}</a>
2525
{% endif %}
2626

2727
<ul class="pagination-list">
2828
<li>
2929
{% if current == first %}
30-
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, knp_pagination_query(query, first)) }}">1</a>
30+
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, knp_pagination_query(query, first, options)) }}">1</a>
3131
{% else %}
32-
<a class="pagination-link" href="{{ path(route, knp_pagination_query(query, first)) }}">1</a>
32+
<a class="pagination-link" href="{{ path(route, knp_pagination_query(query, first, options)) }}">1</a>
3333
{% endif %}
3434
</li>
3535

@@ -43,9 +43,9 @@
4343
{% if first != page and page != last %}
4444
<li>
4545
{% if page == current %}
46-
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, knp_pagination_query(query, page)) }}">{{ page }}</a>
46+
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, knp_pagination_query(query, page, options)) }}">{{ page }}</a>
4747
{% else %}
48-
<a class="pagination-link" aria-label="Goto page {{ page }}" href="{{ path(route, knp_pagination_query(query, page)) }}">{{ page }}</a>
48+
<a class="pagination-link" aria-label="Goto page {{ page }}" href="{{ path(route, knp_pagination_query(query, page, options)) }}">{{ page }}</a>
4949
{% endif %}
5050
</li>
5151
{% endif %}
@@ -59,9 +59,9 @@
5959

6060
<li>
6161
{% if current == last %}
62-
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, knp_pagination_query(query, last)) }}">{{ last }}</a>
62+
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, knp_pagination_query(query, last, options)) }}">{{ last }}</a>
6363
{% else %}
64-
<a class="pagination-link" href="{{ path(route, knp_pagination_query(query, last)) }}">{{ last }}</a>
64+
<a class="pagination-link" href="{{ path(route, knp_pagination_query(query, last, options)) }}">{{ last }}</a>
6565
{% endif %}
6666
</li>
6767
</ul>

templates/Pagination/foundation_v5_pagination.html.twig

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<ul class="pagination">
2222
{% if previous is defined %}
2323
<li class="arrow">
24-
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous)) }}">&laquo; {{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
24+
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">&laquo; {{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
2525
</li>
2626
{% else %}
2727
<li class="arrow unavailable">
@@ -33,11 +33,11 @@
3333

3434
{% if startPage > 1 %}
3535
<li>
36-
<a href="{{ path(route, knp_pagination_query(query, 1)) }}">1</a>
36+
<a href="{{ path(route, knp_pagination_query(query, 1, options)) }}">1</a>
3737
</li>
3838
{% if startPage == 3 %}
3939
<li>
40-
<a href="{{ path(route, knp_pagination_query(query, 2)) }}">2</a>
40+
<a href="{{ path(route, knp_pagination_query(query, 2, options)) }}">2</a>
4141
</li>
4242
{% elseif startPage != 2 %}
4343
<li class="unavailable">
@@ -49,7 +49,7 @@
4949
{% for page in pagesInRange %}
5050
{% if page != current %}
5151
<li>
52-
<a href="{{ path(route, knp_pagination_query(query, page)) }}">
52+
<a href="{{ path(route, knp_pagination_query(query, page, options)) }}">
5353
{{ page }}
5454
</a>
5555
</li>
@@ -69,20 +69,20 @@
6969
</li>
7070
{% else %}
7171
<li>
72-
<a href="{{ path(route, knp_pagination_query(query, (pageCount - 1))) }}">
72+
<a href="{{ path(route, knp_pagination_query(query, (pageCount - 1), options)) }}">
7373
{{ pageCount - 1 }}
7474
</a>
7575
</li>
7676
{% endif %}
7777
{% endif %}
7878
<li>
79-
<a href="{{ path(route, knp_pagination_query(query, pageCount)) }}">{{ pageCount }}</a>
79+
<a href="{{ path(route, knp_pagination_query(query, pageCount, options)) }}">{{ pageCount }}</a>
8080
</li>
8181
{% endif %}
8282

8383
{% if next is defined %}
8484
<li class="arrow">
85-
<a rel="next" href="{{ path(route, knp_pagination_query(query, next)) }}">
85+
<a rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">
8686
{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }} &nbsp;&raquo;
8787
</a>
8888
</li>

templates/Pagination/foundation_v6_pagination.html.twig

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% if previous is defined %}
77
<li class="pagination-previous">
8-
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous)) }}">
8+
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">
99
{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}
1010
</a>
1111
</li>
@@ -17,11 +17,11 @@
1717

1818
{% if startPage > 1 %}
1919
<li>
20-
<a href="{{ path(route, knp_pagination_query(query, 1)) }}">1</a>
20+
<a href="{{ path(route, knp_pagination_query(query, 1, options)) }}">1</a>
2121
</li>
2222
{% if startPage == 3 %}
2323
<li>
24-
<a href="{{ path(route, knp_pagination_query(query, 2)) }}">2</a>
24+
<a href="{{ path(route, knp_pagination_query(query, 2, options)) }}">2</a>
2525
</li>
2626
{% elseif startPage != 2 %}
2727
<li class="ellipsis"></li>
@@ -31,7 +31,7 @@
3131
{% for page in pagesInRange %}
3232
{% if page != current %}
3333
<li>
34-
<a href="{{ path(route, knp_pagination_query(query, page)) }}">
34+
<a href="{{ path(route, knp_pagination_query(query, page, options)) }}">
3535
{{ page }}
3636
</a>
3737
</li>
@@ -46,20 +46,20 @@
4646
<li class="ellipsis"></li>
4747
{% else %}
4848
<li>
49-
<a href="{{ path(route, knp_pagination_query(query, (pageCount - 1))) }}">
49+
<a href="{{ path(route, knp_pagination_query(query, (pageCount - 1), options)) }}">
5050
{{ pageCount - 1 }}
5151
</a>
5252
</li>
5353
{% endif %}
5454
{% endif %}
5555
<li>
56-
<a href="{{ path(route, knp_pagination_query(query, pageCount)) }}">{{ pageCount }}</a>
56+
<a href="{{ path(route, knp_pagination_query(query, pageCount, options)) }}">{{ pageCount }}</a>
5757
</li>
5858
{% endif %}
5959

6060
{% if next is defined %}
6161
<li class="pagination-next">
62-
<a rel="next" href="{{ path(route, knp_pagination_query(query, next)) }}">
62+
<a rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">
6363
{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}
6464
</a>
6565
</li>

templates/Pagination/materialize_pagination.html.twig

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ul class="pagination">
1515
{% if first is defined and current != first %}
1616
<li class="waves-effect">
17-
<a href="{{ path(route, knp_pagination_query(query, first)) }}">
17+
<a href="{{ path(route, knp_pagination_query(query, first, options)) }}">
1818
<i class="material-icons">first_page</i>
1919
</a>
2020
</li>
@@ -28,7 +28,7 @@
2828

2929
{% if previous is defined %}
3030
<li class="waves-effect">
31-
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous)) }}">
31+
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">
3232
<i class="material-icons">chevron_left</i>
3333
</a>
3434
</li>
@@ -43,7 +43,7 @@
4343
{% for page in pagesInRange %}
4444
{% if page != current %}
4545
<li class="waves-effect">
46-
<a href="{{ path(route, knp_pagination_query(query, page)) }}">{{ page }}</a>
46+
<a href="{{ path(route, knp_pagination_query(query, page, options)) }}">{{ page }}</a>
4747
</li>
4848
{% else %}
4949
<li class="active">
@@ -54,7 +54,7 @@
5454

5555
{% if next is defined %}
5656
<li class="waves-effect">
57-
<a rel="next" href="{{ path(route, knp_pagination_query(query, next)) }}">
57+
<a rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">
5858
<i class="material-icons">chevron_right</i>
5959
</a>
6060
</li>
@@ -68,7 +68,7 @@
6868

6969
{% if last is defined and current != last %}
7070
<li class="waves-effect">
71-
<a href="{{ path(route, knp_pagination_query(query, last)) }}">
71+
<a href="{{ path(route, knp_pagination_query(query, last, options)) }}">
7272
<i class="material-icons">last_page</i>
7373
</a>
7474
</li>
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{% if pageCount > 1 %}
22
{% if previous is defined %}
3-
<link rel="prev" href="{{ path(route, knp_pagination_query(query, previous)) }}" />
3+
<link rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}" />
44
{% endif %}
55

66
{% if next is defined %}
7-
<link rel="next" href="{{ path(route, knp_pagination_query(query, next)) }}" />
7+
<link rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}" />
88
{% endif %}
99
{% endif %}

templates/Pagination/semantic_ui_pagination.html.twig

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@
1212
#}
1313
<div class="ui pagination menu">
1414
{% if first is defined and current != first %}
15-
<a class="icon item" href="{{ path(route, knp_pagination_query(query, first)) }}">
15+
<a class="icon item" href="{{ path(route, knp_pagination_query(query, first, options)) }}">
1616
<i class="angle double left icon"></i>
1717
</a>
1818
{% endif %}
1919

2020
{% if previous is defined %}
21-
<a rel="prev" class="item icon" href="{{ path(route, knp_pagination_query(query, previous)) }}">
21+
<a rel="prev" class="item icon" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">
2222
<i class="angle left icon"></i>
2323
</a>
2424
{% endif %}
2525

2626
{% for page in pagesInRange %}
2727
{% if page != current %}
28-
<a class="item" href="{{ path(route, knp_pagination_query(query, page)) }}">{{ page }}</a>
28+
<a class="item" href="{{ path(route, knp_pagination_query(query, page, options)) }}">{{ page }}</a>
2929
{% else %}
3030
<span class="active item">{{ page }}</span>
3131
{% endif %}
3232

3333
{% endfor %}
3434

3535
{% if next is defined %}
36-
<a rel="next" class="icon item" href="{{ path(route, knp_pagination_query(query, next)) }}">
36+
<a rel="next" class="icon item" href="{{ path(route, knp_pagination_query(query, next, options)) }}">
3737
<i class="angle right icon"></i>
3838
</a>
3939
{% endif %}
4040

4141
{% if last is defined and current != last %}
42-
<a class="icon item" href="{{ path(route, knp_pagination_query(query, last)) }}">
42+
<a class="icon item" href="{{ path(route, knp_pagination_query(query, last, options)) }}">
4343
<i class="angle right double icon"></i>
4444
</a>
4545
{% endif %}

templates/Pagination/sliding.html.twig

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
<div class="pagination">
44
{% if first is defined and current != first %}
55
<span class="first">
6-
<a href="{{ path(route, knp_pagination_query(query, first)) }}">&lt;&lt;</a>
6+
<a href="{{ path(route, knp_pagination_query(query, first, options)) }}">&lt;&lt;</a>
77
</span>
88
{% endif %}
99

1010
{% if previous is defined %}
1111
<span class="previous">
12-
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous)) }}">&lt;</a>
12+
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">&lt;</a>
1313
</span>
1414
{% endif %}
1515

1616
{% for page in pagesInRange %}
1717
{% if page != current %}
1818
<span class="page">
19-
<a href="{{ path(route, knp_pagination_query(query, page)) }}">{{ page }}</a>
19+
<a href="{{ path(route, knp_pagination_query(query, page, options)) }}">{{ page }}</a>
2020
</span>
2121
{% else %}
2222
<span class="current">{{ page }}</span>
@@ -25,13 +25,13 @@
2525

2626
{% if next is defined %}
2727
<span class="next">
28-
<a rel="next" href="{{ path(route, knp_pagination_query(query, next)) }}">&gt;</a>
28+
<a rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">&gt;</a>
2929
</span>
3030
{% endif %}
3131

3232
{% if last is defined and current != last %}
3333
<span class="last">
34-
<a href="{{ path(route, knp_pagination_query(query, last)) }}">&gt;&gt;</a>
34+
<a href="{{ path(route, knp_pagination_query(query, last, options)) }}">&gt;&gt;</a>
3535
</span>
3636
{% endif %}
3737
</div>

templates/Pagination/tailwindcss_pagination.html.twig

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
<div class="flex items-baseline flex-row border border-gray-400 rounded-sm w-auto">
55
{% if first is defined and current != first %}
66
<span class="bg-white text-blue-600 px-3 py-2 text-lg border-r border-gray-400 font-bold">
7-
<a href="{{ path(route, knp_pagination_query(query, first)) }}">&lt;&lt;</a>
7+
<a href="{{ path(route, knp_pagination_query(query, first, options)) }}">&lt;&lt;</a>
88
</span>
99
{% endif %}
1010

1111
{% if previous is defined %}
1212
<span class="bg-white text-blue-600 px-3 text-lg py-2 border-r border-gray-400">
13-
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous)) }}">&lt;</a>
13+
<a rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">&lt;</a>
1414
</span>
1515
{% endif %}
1616

1717
{% for page in pagesInRange %}
1818
{% if page != current %}
1919
<span class="bg-white text-blue-600 px-3 py-2 text-lg border-r border-gray-400">
20-
<a href="{{ path(route, knp_pagination_query(query, page)) }}">{{ page }}</a>
20+
<a href="{{ path(route, knp_pagination_query(query, page, options)) }}">{{ page }}</a>
2121
</span>
2222
{% else %}
2323
<span class="bg-blue-600 text-white px-3 py-2 text-lg font-bold">{{ page }}</span>
@@ -26,13 +26,13 @@
2626

2727
{% if next is defined %}
2828
<span class="bg-white text-blue-600 px-3 py-2 text-lg border-r border-gray-400">
29-
<a rel="next" href="{{ path(route, knp_pagination_query(query, next)) }}">&gt;</a>
29+
<a rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">&gt;</a>
3030
</span>
3131
{% endif %}
3232

3333
{% if last is defined and current != last %}
3434
<span class="bg-white text-blue-600 px-3 py-2 text-lg border-gray-400 font-bold">
35-
<a href="{{ path(route, knp_pagination_query(query, last)) }}">&gt;&gt;</a>
35+
<a href="{{ path(route, knp_pagination_query(query, last, options)) }}">&gt;&gt;</a>
3636
</span>
3737
{% endif %}
3838
</div>

0 commit comments

Comments
 (0)