It looks like libraries_load_files() is still using drupal_add_js() and drupal_add_css() ... ~line 683: call_user_func('drupal_add_' . $type, $data, $options) . Given that drupal_add_* functions appear to have recently been removed (change record) libraries_load() will no longer deal with js and css defined within a module's hook_libraries_info() implementation. Because of this calling libraries_load() will currently trigger an error (e.g., call_user_func() expects parameter 1 to be a valid callback....).

I'm not sure what this means for the module (or even how to categorize this issue), but it would be interesting if anyone can share thoughts on this. Perhaps an API function is needed to fetch a version of a $library array that can easily be merged directly into an '#attached' array on a render array?

CommentFileSizeAuthor
#1 2183087-1.patch3.55 KBtstoeckler
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Title: drupal_add_js and drupal_add_css obsolete » drupal_add_js/css and variable_get/set obsolete
Status: Active » Needs review
FileSize
3.55 KB

Thanks for reporting this!

We were also still using variable_get/set(), which was also removed.

Comitted attached patch to see if that unbreaks 8.x-3.x.

http://drupalcode.org/project/libraries.git/commit/632c2ea3681de4b415db6...

Status: Needs review » Needs work

The last submitted patch, 1: 2183087-1.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Fixed

Status: Fixed » Needs work

The last submitted patch, 1: 2183087-1.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Fixed
tstoeckler’s picture

Title: drupal_add_js/css and variable_get/set obsolete » Find a way around _drupal_add_js/css
Status: Fixed » Active

Or in fact let's leave this open to address the bigger issue that you mentioned in the OP.

tstoeckler’s picture

So really this is dependant upon decoupling the different library types. What we really want is to able to call libraries_attach_library($render_array, $library_name, $variant_name), similar to drupal_attach_tabledrag in in D8. That, however, makes no sense for PHP files, that has nothing to do with render arrays. Hmm....

rjacobs’s picture

Having a function like libraries_attach_library() was in-line with the solution that I had in mind. I'm actually (temporarily) using a local method to accomplish something similar to this in a 8.x module that I'm working on now ... see code here.

You mentioned that this has no relevance for php libraries, which would be true. I suppose it would only apply to libraries that declare 'js' and 'css' values in their 'files' definition. I'm wondering however if this would be a problem. An "attach" function like this could just go unused by code that loads a php-only library, and if it did use it, an unaltered array would come back. That said, I may still be missing some of the fundamental ways that Libraries API is changing for D8.

rjacobs’s picture