function SystemMenuNavigationBlockTest::convertBuiltMenuToIdTree

Same name and namespace in other branches
  1. 10 core/modules/navigation/tests/src/Kernel/SystemMenuNavigationBlockTest.php \Drupal\Tests\navigation\Kernel\SystemMenuNavigationBlockTest::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 SystemMenuNavigationBlockTest::convertBuiltMenuToIdTree()
SystemMenuNavigationBlockTest::testConfigLevelDepth in core/modules/navigation/tests/src/Kernel/SystemMenuNavigationBlockTest.php
Tests the config start level and depth.

File

core/modules/navigation/tests/src/Kernel/SystemMenuNavigationBlockTest.php, line 293

Class

SystemMenuNavigationBlockTest
Tests \Drupal\navigation\Plugin\Block\SystemMenuNavigationBlock.

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.