@@ -254,14 +254,15 @@ protected function _beforeToHtml()
254
254
255
255
256
256
/**
257
+ * Reorder the tabs.
258
+ *
257
259
* @return array
258
260
*/
259
261
private function reorderTabs ()
260
262
{
261
263
$ orderByIdentity = [];
262
264
$ orderByPosition = [];
263
-
264
- $ position = 100 ;
265
+ $ position = 100 ;
265
266
266
267
/**
267
268
* Set the initial positions for each tab.
@@ -277,9 +278,21 @@ private function reorderTabs()
277
278
278
279
$ position += 100 ;
279
280
}
280
-
281
+
282
+ return $ this ->applyTabsCorrectOrder ($ orderByPosition , $ orderByIdentity );
283
+ }
284
+
285
+
286
+ /**
287
+ * @param array $orderByPosition
288
+ * @param array $orderByIdentity
289
+ *
290
+ * @return array
291
+ */
292
+ private function applyTabsCorrectOrder (array $ orderByPosition , array $ orderByIdentity )
293
+ {
281
294
$ positionFactor = 1 ;
282
-
295
+
283
296
/**
284
297
* Rearrange the positions by using the after tag for each tab.
285
298
*
@@ -291,26 +304,39 @@ private function reorderTabs()
291
304
$ positionFactor = 1 ;
292
305
continue ;
293
306
}
294
-
307
+
295
308
$ grandPosition = $ orderByIdentity [$ tab ->getAfter ()]->getPosition ();
296
309
$ newPosition = $ grandPosition + $ positionFactor ;
297
-
310
+
298
311
unset($ orderByPosition [$ position ]);
299
312
$ orderByPosition [$ newPosition ] = $ tab ;
300
313
$ tab ->setPosition ($ newPosition );
301
-
314
+
302
315
$ positionFactor ++;
303
316
}
304
-
317
+
318
+ return $ this ->finalTabsSortOrder ($ orderByPosition );
319
+ }
320
+
321
+
322
+ /**
323
+ * Apply the last sort order to tabs.
324
+ *
325
+ * @param array $orderByPosition
326
+ *
327
+ * @return array
328
+ */
329
+ private function finalTabsSortOrder (array $ orderByPosition )
330
+ {
305
331
ksort ($ orderByPosition );
306
-
332
+
307
333
$ ordered = [];
308
-
334
+
309
335
/** @var TabInterface $tab */
310
336
foreach ($ orderByPosition as $ tab ) {
311
337
$ ordered [$ tab ->getId ()] = $ tab ;
312
338
}
313
-
339
+
314
340
return $ ordered ;
315
341
}
316
342
0 commit comments