function toolbar_get_rendered_subtrees

Same name in other branches
  1. 9 core/modules/toolbar/toolbar.module \toolbar_get_rendered_subtrees()
  2. 8.9.x core/modules/toolbar/toolbar.module \toolbar_get_rendered_subtrees()
  3. 11.x core/modules/toolbar/toolbar.module \toolbar_get_rendered_subtrees()

Returns the rendered subtree of each top-level toolbar link.

Return value

array An array with the following key-value pairs:

  • 'subtrees': the rendered subtrees
  • 'cacheability: the associated cacheability.
2 calls to toolbar_get_rendered_subtrees()
ToolbarController::subtreesAjax in core/modules/toolbar/src/Controller/ToolbarController.php
Returns an AJAX response to render the toolbar subtrees.
_toolbar_get_subtrees_hash in core/modules/toolbar/toolbar.module
Returns the hash of the user-rendered toolbar subtrees and cacheability.

File

core/modules/toolbar/toolbar.module, line 267

Code

function toolbar_get_rendered_subtrees() {
    $data = [
        '#pre_render' => [
            [
                ToolbarController::class,
                'preRenderGetRenderedSubtrees',
            ],
        ],
        '#cache' => [
            'keys' => [
                'toolbar_rendered_subtrees',
            ],
        ],
        '#cache_properties' => [
            '#subtrees',
        ],
    ];
    
    /** @var \Drupal\Core\Render\Renderer $renderer */
    $renderer = \Drupal::service('renderer');
    // The pre_render process populates $data during the render pipeline.
    // We need to pass by reference so that populated data can be returned and
    // used to resolve cacheability.
    $renderer->executeInRenderContext(new RenderContext(), function () use ($renderer, &$data) {
        $renderer->render($data);
    });
    return [
        $data['#subtrees'],
        CacheableMetadata::createFromRenderArray($data),
    ];
}

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