function Renderer::doRenderRoot

See the docs for ::render().

2 calls to Renderer::doRenderRoot()
Renderer::render in core/lib/Drupal/Core/Render/Renderer.php
Renders HTML given a structured array tree.
Renderer::renderInIsolation in core/lib/Drupal/Core/Render/Renderer.php
Renders final HTML in situations where no assets are needed.

File

core/lib/Drupal/Core/Render/Renderer.php, line 229

Class

Renderer
Turns a render array into an HTML string.

Namespace

Drupal\Core\Render

Code

protected function doRenderRoot(array &$elements, RenderContext $context) : string|MarkupInterface {
    if (!$elements) {
        return '';
    }
    // Set the bubbleable rendering metadata that has configurable defaults
    // to ensure that the final render array definitely has these configurable
    // defaults, even when no subtree is render cached.
    $required_cache_contexts = $this->rendererConfig['required_cache_contexts'];
    if (isset($elements['#cache']['contexts'])) {
        $elements['#cache']['contexts'] = Cache::mergeContexts($elements['#cache']['contexts'], $required_cache_contexts);
    }
    else {
        $elements['#cache']['contexts'] = $required_cache_contexts;
    }
    // Render the elements normally.
    $return = $this->doRender($elements, $context);
    // If there is no output, return early as placeholders can't make a
    // difference.
    if ((string) $return === '') {
        return $return;
    }
    // Only when rendering the root do placeholders have to be processed. If we
    // were to replace them while rendering cacheable nested elements, their
    // cacheable metadata would still bubble all the way up the render tree,
    // effectively making the use of placeholders pointless.
    $this->replacePlaceholders($elements);
    return $elements['#markup'];
}

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