function DefaultMenuLinkTreeManipulators::flatten
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::flatten()
- 10 core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::flatten()
- 11.x core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators::flatten()
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
-
core/
lib/ Drupal/ Core/ Menu/ DefaultMenuLinkTreeManipulators.php, line 251
Class
- DefaultMenuLinkTreeManipulators
- Provides a couple of menu link tree manipulators.
Namespace
Drupal\Core\MenuCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.