function CommonTestThemeHooks::pageAttachments

Implements hook_page_attachments().

Attributes

#[Hook('page_attachments')]

See also

\Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions()

File

core/modules/system/tests/modules/common_test/src/Hook/CommonTestThemeHooks.php, line 68

Class

CommonTestThemeHooks
Hook implementations for common_test.

Namespace

Drupal\common_test\Hook

Code

public function pageAttachments(array &$page) : void {
  $page['#attached']['library'][] = 'core/foo';
  $page['#attached']['library'][] = 'core/bar';
  $page['#cache']['tags'] = [
    'example',
  ];
  $page['#cache']['contexts'] = [
    'user.permissions',
  ];
  if (\Drupal::state()->get('common_test.hook_page_attachments.descendant_attached', FALSE)) {
    $page['content']['#attached']['library'][] = 'core/jquery';
  }
  if (\Drupal::state()->get('common_test.hook_page_attachments.render_array', FALSE)) {
    $page['something'] = [
      '#markup' => 'test',
    ];
  }
  if (\Drupal::state()->get('common_test.hook_page_attachments.early_rendering', FALSE)) {
    // Do some early rendering.
    $element = [
      '#markup' => '123',
    ];
    \Drupal::service('renderer')->render($element);
  }
}

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