Hello, I'm trying to use libraries module but I have this issue. (using this docu: https://www.drupal.org/node/2170763)

I defined my library with hook_libraries_info and use hook_page_attachments to load it because in D8 hook_page_build is deprecated.

But i get this error:
Uncaught PHP Exception LogicException: "You are not allowed to use libraries_load in #attached" at core/includes/common.inc line 683

Any idea?
Thanks

Comments

facine’s picture

Issue summary: View changes
rjacobs’s picture

Status: Active » Closed (duplicate)
Related issues: +#2183087: Find a way around _drupal_add_js/css

Technically speaking I think what you are asking is very similar to what was discussed in #2183087: Find a way around _drupal_add_js/css.

The way that libraries will be handled/loaded now that callbacks are not allowed in #attached properties (and apparently hook_page_attachments()) is still being discussed. Some more info about that is also available in #1386368: Register Libraries in hook_library().

medienverbinder’s picture

I get the same error message when i try to #attach libraries defined with hook_libraries_info to a simple block module via public function build().

 LogicException: You are not allowed to use libraries_load in #attached. in Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments() (line 150 of /var/www/d8/htdocs/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php).
florianmuellerCH’s picture

For those that stumble upon this site having the same Problem as medienverbinder:

When you define the library in a render array, be sure to use the array key "library" and not "libraries" because libraries is a separate module, and render array attachments expect the key "library". Small but a game changer.