function HOOK_page_attachments_alter in AT Tools 8
Same name and namespace in other branches
- 8.3 at_theme_generator/starterkits/starterkit/STARTERKIT.theme \HOOK_page_attachments_alter()
- 8.2 at_theme_generator/starterkits/starterkit/STARTERKIT.theme \HOOK_page_attachments_alter()
Alter attachments (typically assets) to a page before it is rendered.
Use this hook when you want to remove or alter attachments on the page, or add attachments to the page that depend on another module's attachments (this hook runs after hook_page_attachments().
Parameters
array &$page: An empty renderable array representing the page.
See also
File
- at_theme_generator/
starterkits/ starterkit/ THEMENAME.theme, line 101
Code
function HOOK_page_attachments_alter(array &$page) {
$theme = 'HOOK';
// Attach module dependant libraries.
// These libraries are declared in your themeName.libraries.yml and we only
// load if the module is installed.
$module_libraries = array(
'addtoany',
'ds',
'social_media_links',
'superfish',
);
$theme_libraries = \Drupal::service('library.discovery')
->getLibrariesByExtension($theme);
foreach ($module_libraries as $module_library) {
if (array_key_exists($module_library, $theme_libraries) && \Drupal::moduleHandler()
->moduleExists($module_library) === TRUE) {
$page['#attached']['library'][] = "{$theme}/{$module_library}";
}
}
}