Skip to content

Commit 4ac09bf

Browse files
tiagosampaiomage2pratik
authored andcommitted
Sort order was split into few private methods.
1 parent 1aec473 commit 4ac09bf

File tree

1 file changed

+37
-11
lines changed
  • app/code/Magento/Backend/Block/Widget

1 file changed

+37
-11
lines changed

app/code/Magento/Backend/Block/Widget/Tabs.php

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,15 @@ protected function _beforeToHtml()
251251

252252

253253
/**
254+
* Reorder the tabs.
255+
*
254256
* @return array
255257
*/
256258
private function reorderTabs()
257259
{
258260
$orderByIdentity = [];
259261
$orderByPosition = [];
260-
261-
$position = 100;
262+
$position = 100;
262263

263264
/**
264265
* Set the initial positions for each tab.
@@ -274,9 +275,21 @@ private function reorderTabs()
274275

275276
$position += 100;
276277
}
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+
{
278291
$positionFactor = 1;
279-
292+
280293
/**
281294
* Rearrange the positions by using the after tag for each tab.
282295
*
@@ -288,26 +301,39 @@ private function reorderTabs()
288301
$positionFactor = 1;
289302
continue;
290303
}
291-
304+
292305
$grandPosition = $orderByIdentity[$tab->getAfter()]->getPosition();
293306
$newPosition = $grandPosition + $positionFactor;
294-
307+
295308
unset($orderByPosition[$position]);
296309
$orderByPosition[$newPosition] = $tab;
297310
$tab->setPosition($newPosition);
298-
311+
299312
$positionFactor++;
300313
}
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+
{
302328
ksort($orderByPosition);
303-
329+
304330
$ordered = [];
305-
331+
306332
/** @var TabInterface $tab */
307333
foreach ($orderByPosition as $tab) {
308334
$ordered[$tab->getId()] = $tab;
309335
}
310-
336+
311337
return $ordered;
312338
}
313339

0 commit comments

Comments
 (0)