W3cubDocs

/Drupal 8

public function HtmlRenderer::invokePageAttachmentHooks

public HtmlRenderer::invokePageAttachmentHooks(array &$page)

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()

File

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

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 = [];
  foreach ($this->moduleHandler->getImplementations('page_attachments') as $module) {
    $function = $module . '_page_attachments';
    $function($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);
  \Drupal::theme()->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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!MainContent!HtmlRenderer.php/function/HtmlRenderer::invokePageAttachmentHooks/8.1.x