function NavigationTestHooks::navigationContentTop

Implements hook_navigation_content_top().

File

core/modules/navigation/tests/navigation_test/src/Hook/NavigationTestHooks.php, line 41

Class

NavigationTestHooks
Hooks implementations for navigation_test module.

Namespace

Drupal\navigation_test\Hook

Code

public function navigationContentTop() : array {
    if (\Drupal::keyValue('navigation_test')->get('content_top')) {
        $items = [
            'navigation_foo' => [
                '#markup' => 'foo',
            ],
            'navigation_bar' => [
                '#markup' => 'bar',
            ],
            'navigation_baz' => [
                '#markup' => 'baz',
            ],
        ];
    }
    else {
        $items = [
            'navigation_foo' => [],
            'navigation_bar' => [],
            'navigation_baz' => [],
        ];
    }
    // Add cache tags to our items to express a made up dependency to test
    // cacheability. Note that as we're always returning the same items,
    // sometimes only with cacheability metadata. By doing this we're testing
    // conditional rendering of content_top items.
    foreach ($items as &$element) {
        CacheableMetadata::createFromRenderArray($element)->addCacheTags([
            'navigation_test',
        ])
            ->applyTo($element);
    }
    return $items;
}

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