\hook_page_attachments
function
Add attachments (typically assets) to a page before it is rendered.

Add attachments (typically assets) to a page before it is rendered.

Use this hook when you want to conditionally add attachments to a page.

If you want to alter the attachments added by other modules or if your module depends on the elements of other modules, use hook_page_attachments_alter() instead, which runs after this hook.

If you try to add anything but #attached and #cache to the array, an exception is thrown.

Comments

vbouchet’s picture

Not sure it is on purpose (maybe a global rule I was not aware of) but only modules implementations of hook_page_attachments are invoked whereas both modules and themes implementations of hook_page_attachments_alter() are invoked.