This repository was archived by the owner on May 2, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -160,14 +160,23 @@ public function normalizeValues()
160160 * We use this to render a whole set of form types, which should be displayed
161161 * in some order. When you want to be able to get a form field by it's name
162162 * and place it on a custom place, use the getNamedValues() method.
163+ *
164+ * @param string $order
163165 *
164166 * @return array
165167 */
166- public function getSortedValues ()
168+ public function getSortedValues ($ order = ' asc ' )
167169 {
168170 $ values = $ this ->values ->toArray ();
169- usort ($ values , function ($ value1 , $ value2 ) {
170- return ($ value1 ->getAttribute ()->getSort () < $ value2 ->getAttribute ()->getSort ()) ? 1 : -1 ;
171+ usort ($ values , function ($ a , $ b ) use ($ order ) {
172+ $ left = $ a ->getAttribute ()->getSort ();
173+ $ right = $ b ->getAttribute ()->getSort ();
174+
175+ if ($ order == 'desc ' ) {
176+ return ($ left < $ right ) ? 1 : -1 ;
177+ }
178+
179+ return ($ left > $ right ) ? 1 : -1 ;
171180 });
172181
173182 return $ values ;
@@ -186,9 +195,9 @@ public function getSortedValues()
186195 *
187196 * @return array
188197 */
189- public function getNamedValues ()
198+ public function getNamedValues ($ order = ' asc ' )
190199 {
191- $ values = $ this ->getSortedValues ();
200+ $ values = $ this ->getSortedValues ($ order );
192201
193202 $ valueArray = [];
194203 foreach ($ values as $ value ) {
You can’t perform that action at this time.
0 commit comments