33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Ui \Component ;
78
89/**
10+ * Class Paging
11+ *
912 * @api
1013 * @since 100.0.2
1114 */
1215class Paging extends AbstractComponent
1316{
1417 const NAME = 'paging ' ;
1518
19+ /**
20+ * Default paging options
21+ *
22+ * @var array
23+ */
24+ private $ defaultOptions = [
25+ '20 ' => [
26+ 'value ' => 20 ,
27+ 'label ' => 20
28+ ],
29+ '30 ' => [
30+ 'value ' => 30 ,
31+ 'label ' => 30
32+ ],
33+ '50 ' => [
34+ 'value ' => 50 ,
35+ 'label ' => 50
36+ ],
37+ '100 ' => [
38+ 'value ' => 100 ,
39+ 'label ' => 100
40+ ],
41+ '200 ' => [
42+ 'value ' => 200 ,
43+ 'label ' => 200
44+ ],
45+ ];
46+
47+ /**
48+ * Default page size
49+ *
50+ * @var int
51+ */
52+ private $ defaultPageSize = 20 ;
53+
1654 /**
1755 * Default component data
1856 *
1957 * @var array
2058 */
2159 protected $ _data = [
2260 'config ' => [
23- 'options ' => [
24- '20 ' => [
25- 'value ' => 20 ,
26- 'label ' => 20
27- ],
28- '30 ' => [
29- 'value ' => 30 ,
30- 'label ' => 30
31- ],
32- '50 ' => [
33- 'value ' => 50 ,
34- 'label ' => 50
35- ],
36- '100 ' => [
37- 'value ' => 100 ,
38- 'label ' => 100
39- ],
40- '200 ' => [
41- 'value ' => 200 ,
42- 'label ' => 200
43- ],
44- ],
45- 'pageSize ' => 20 ,
4661 'current ' => 1
4762 ]
4863 ];
@@ -65,13 +80,13 @@ public function getComponentName()
6580 public function prepare ()
6681 {
6782 $ this ->prepareOptions ();
83+ $ this ->preparePageSize ();
6884 $ paging = $ this ->getContext ()->getRequestParam ('paging ' );
6985 if (!isset ($ paging ['notLimits ' ])) {
7086 $ this ->getContext ()
7187 ->getDataProvider ()
7288 ->setLimit ($ this ->getOffset ($ paging ), $ this ->getSize ($ paging ));
7389 }
74-
7590 parent ::prepare ();
7691 }
7792
@@ -83,12 +98,26 @@ public function prepare()
8398 protected function prepareOptions ()
8499 {
85100 $ config = $ this ->getData ('config ' );
86- if (isset ($ config ['options ' ])) {
87- $ config ['options ' ] = array_values ($ config ['options ' ]);
88- foreach ($ config ['options ' ] as &$ item ) {
89- $ item ['value ' ] = (int ) $ item ['value ' ];
90- }
91- unset($ item );
101+ if (!isset ($ config ['options ' ])) {
102+ $ config ['options ' ] = $ this ->defaultOptions ;
103+ }
104+ foreach ($ config ['options ' ] as &$ item ) {
105+ $ item ['value ' ] = (int )$ item ['value ' ];
106+ }
107+ unset($ item );
108+ $ this ->setData ('config ' , $ config );
109+ }
110+
111+ /**
112+ * Prepare page size
113+ *
114+ * @return void
115+ */
116+ private function preparePageSize ()
117+ {
118+ $ config = $ this ->getData ('config ' );
119+ if (!isset ($ config ['pageSize ' ])) {
120+ $ config ['pageSize ' ] = $ this ->defaultPageSize ;
92121 $ this ->setData ('config ' , $ config );
93122 }
94123 }
@@ -102,7 +131,7 @@ protected function prepareOptions()
102131 protected function getOffset ($ paging )
103132 {
104133 $ defaultPage = $ this ->getData ('config/current ' ) ?: 1 ;
105- return (int ) (isset ($ paging ['current ' ]) ? $ paging ['current ' ] : $ defaultPage );
134+ return (int )(isset ($ paging ['current ' ]) ? $ paging ['current ' ] : $ defaultPage );
106135 }
107136
108137 /**
@@ -113,7 +142,6 @@ protected function getOffset($paging)
113142 */
114143 protected function getSize ($ paging )
115144 {
116- $ defaultLimit = $ this ->getData ('config/pageSize ' ) ?: 20 ;
117- return (int ) (isset ($ paging ['pageSize ' ]) ? $ paging ['pageSize ' ] : $ defaultLimit );
145+ return (int )(isset ($ paging ['pageSize ' ]) ? $ paging ['pageSize ' ] : $ this ->getData ('config/pageSize ' ));
118146 }
119147}
0 commit comments