You are here

public function AnonymousMenuLinkTreeManipulator::flatten in footermap: a footer site map 8

Flattens the tree to a single level.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu link tree to manipulate.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] The manipulated menu link tree.

File

src/Menu/AnonymousMenuLinkTreeManipulator.php, line 260

Class

AnonymousMenuLinkTreeManipulator
Provides an anonymous-based menu link tree manipulator.

Namespace

Drupal\footermap\Menu

Code

public function flatten(array $tree) {
  foreach ($tree as $key => $element) {
    if ($tree[$key]->subtree) {
      $tree += $this
        ->flatten($tree[$key]->subtree);
    }
    $tree[$key]->subtree = [];
  }
  return $tree;
}