8.5.x common_test.module common_test_page_attachments(array &$page)
8.0.x common_test.module common_test_page_attachments(array &$page)
8.1.x common_test.module common_test_page_attachments(array &$page)
8.2.x common_test.module common_test_page_attachments(array &$page)
8.3.x common_test.module common_test_page_attachments(array &$page)
8.4.x common_test.module common_test_page_attachments(array &$page)
8.6.x common_test.module common_test_page_attachments(array &$page)

Implements hook_page_attachments().

See also

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

File

core/modules/system/tests/modules/common_test/common_test.module, line 223
Helper module for the Common tests.

Code

function common_test_page_attachments(array &$page) {
  $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',
    ];
  }
}