@@ -254,14 +254,15 @@ protected function _beforeToHtml()
254254
255255
256256 /**
257+ * Reorder the tabs.
258+ *
257259 * @return array
258260 */
259261 private function reorderTabs ()
260262 {
261263 $ orderByIdentity = [];
262264 $ orderByPosition = [];
263-
264- $ position = 100 ;
265+ $ position = 100 ;
265266
266267 /**
267268 * Set the initial positions for each tab.
@@ -277,9 +278,21 @@ private function reorderTabs()
277278
278279 $ position += 100 ;
279280 }
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+ {
281294 $ positionFactor = 1 ;
282-
295+
283296 /**
284297 * Rearrange the positions by using the after tag for each tab.
285298 *
@@ -291,26 +304,39 @@ private function reorderTabs()
291304 $ positionFactor = 1 ;
292305 continue ;
293306 }
294-
307+
295308 $ grandPosition = $ orderByIdentity [$ tab ->getAfter ()]->getPosition ();
296309 $ newPosition = $ grandPosition + $ positionFactor ;
297-
310+
298311 unset($ orderByPosition [$ position ]);
299312 $ orderByPosition [$ newPosition ] = $ tab ;
300313 $ tab ->setPosition ($ newPosition );
301-
314+
302315 $ positionFactor ++;
303316 }
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+ {
305331 ksort ($ orderByPosition );
306-
332+
307333 $ ordered = [];
308-
334+
309335 /** @var TabInterface $tab */
310336 foreach ($ orderByPosition as $ tab ) {
311337 $ ordered [$ tab ->getId ()] = $ tab ;
312338 }
313-
339+
314340 return $ ordered ;
315341 }
316342
0 commit comments