function NavigationMenuBlockTest::convertBuiltMenuToIdTree

Same name in other branches
  1. 11.x core/modules/navigation/tests/src/Kernel/NavigationMenuBlockTest.php \Drupal\Tests\navigation\Kernel\NavigationMenuBlockTest::convertBuiltMenuToIdTree()

Helper method to allow for easy menu link tree structure assertions.

Converts the result of MenuLinkTree::build() in a "menu link ID tree".

Parameters

array $build: The return value of MenuLinkTree::build()

Return value

array The "menu link ID tree" representation of the given render array.

1 call to NavigationMenuBlockTest::convertBuiltMenuToIdTree()
NavigationMenuBlockTest::testConfigLevelDepth in core/modules/navigation/tests/src/Kernel/NavigationMenuBlockTest.php
Tests the config start level and depth.

File

core/modules/navigation/tests/src/Kernel/NavigationMenuBlockTest.php, line 367

Class

NavigationMenuBlockTest
Tests \Drupal\navigation\Plugin\Block\NavigationMenuBlock.

Namespace

Drupal\Tests\navigation\Kernel

Code

protected function convertBuiltMenuToIdTree(array $build) {
    $level = [];
    foreach (Element::children($build) as $id) {
        $level[$id] = [];
        if (isset($build[$id]['below'])) {
            $level[$id] = $this->convertBuiltMenuToIdTree($build[$id]['below']);
        }
    }
    return $level;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.