function common_test_page_attachments_alter in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/common_test/common_test.module \common_test_page_attachments_alter()
Implements hook_page_attachments_alter().
See also
\Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions()
File
- core/
modules/ system/ tests/ modules/ common_test/ common_test.module, line 227 - Helper module for the Common tests.
Code
function common_test_page_attachments_alter(array &$page) {
// Remove a library that was added in common_test_page_attachments(), to test
// that this hook can do what it claims to do.
if (isset($page['#attached']['library']) && ($index = array_search('core/bar', $page['#attached']['library'])) && $index !== FALSE) {
unset($page['#attached']['library'][$index]);
}
$page['#attached']['library'][] = 'core/baz';
$page['#cache']['tags'] = [
'example',
];
$page['#cache']['contexts'] = [
'user.permissions',
];
if (\Drupal::state()
->get('common_test.hook_page_attachments_alter.descendant_attached', FALSE)) {
$page['content']['#attached']['library'][] = 'core/jquery';
}
if (\Drupal::state()
->get('common_test.hook_page_attachments_alter.render_array', FALSE)) {
$page['something'] = [
'#markup' => 'test',
];
}
}