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