You are here

public function RenderCheeseburgerMenuBlock::sortMenus in Cheeseburger Menu 8.4

Sorts menu based on menu_weight.

1 call to RenderCheeseburgerMenuBlock::sortMenus()
RenderCheeseburgerMenuBlock::formTree in src/Controller/RenderCheeseburgerMenuBlock.php
Handles forming tree for menus.

File

src/Controller/RenderCheeseburgerMenuBlock.php, line 317
Controller used for rendering block.

Class

RenderCheeseburgerMenuBlock
Class RenderCheeseburgerMenuBlock.

Namespace

Drupal\cheeseburger_menu\Controller

Code

public function sortMenus(&$tree) {
  do {
    $change = FALSE;
    for ($i = 0; $i < count($tree) - 1; $i++) {
      if ($tree[$i]['menu_weight'] > $tree[$i + 1]['menu_weight']) {
        $temp = $tree[$i];
        $tree[$i] = $tree[$i + 1];
        $tree[$i + 1] = $temp;
        $change = TRUE;
      }
    }
  } while ($change === TRUE);
}