function SystemMenuBlockTest::convertBuiltMenuToIdTree

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::convertBuiltMenuToIdTree()
  2. 10 core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::convertBuiltMenuToIdTree()
  3. 11.x core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::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.

2 calls to SystemMenuBlockTest::convertBuiltMenuToIdTree()
SystemMenuBlockTest::testConfigExpanded in core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php
Tests the config expanded option.
SystemMenuBlockTest::testConfigLevelDepth in core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php
Tests the config start level and depth.

File

core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php, line 382

Class

SystemMenuBlockTest
Tests <a href="/api/drupal/core%21modules%21system%21src%21Plugin%21Block%21SystemMenuBlock.php/class/SystemMenuBlock/8.9.x" title="Provides a generic Menu block." class="local">\Drupal\system\Plugin\Block\SystemMenuBlock</a>.

Namespace

Drupal\Tests\system\Kernel\Block

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.