function HtmlRenderer::invokePageAttachmentHooks

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php \Drupal\Core\Render\MainContent\HtmlRenderer::invokePageAttachmentHooks()
  2. 8.9.x core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php \Drupal\Core\Render\MainContent\HtmlRenderer::invokePageAttachmentHooks()
  3. 11.x core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php \Drupal\Core\Render\MainContent\HtmlRenderer::invokePageAttachmentHooks()

Invokes the page attachment hooks.

@internal

Parameters

array &$page: A #type 'page' render array, for which the page attachment hooks will be invoked and to which the results will be added.

Throws

\LogicException

See also

hook_page_attachments()

hook_page_attachments_alter()

1 call to HtmlRenderer::invokePageAttachmentHooks()
HtmlRenderer::prepare in core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
Prepares the HTML body: wraps the main content in #type 'page'.

File

core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php, line 305

Class

HtmlRenderer
Default main content renderer for HTML requests.

Namespace

Drupal\Core\Render\MainContent

Code

public function invokePageAttachmentHooks(array &$page) {
    // Modules can add attachments.
    $attachments = [];
    $this->moduleHandler
        ->invokeAllWith('page_attachments', function (callable $hook, string $module) use (&$attachments) {
        $hook($attachments);
    });
    if (array_diff(array_keys($attachments), [
        '#attached',
        '#cache',
    ]) !== []) {
        throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments().');
    }
    // Modules and themes can alter page attachments.
    $this->moduleHandler
        ->alter('page_attachments', $attachments);
    $this->themeManager
        ->alter('page_attachments', $attachments);
    if (array_diff(array_keys($attachments), [
        '#attached',
        '#cache',
    ]) !== []) {
        throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments_alter().');
    }
    // Merge the attachments onto the $page render array.
    $page = $this->renderer
        ->mergeBubbleableMetadata($page, $attachments);
}

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