I have a library module which defines a library and two variants:
library
variant1
variant2
The library has files, each variant has a subset of files in the library.
If you request a variant:
libraries_load('library', 'variant1')
first, then that is what is returned for all further requests to libraries load independent of the presence or absence of variant.
The following patch:
Index: sites/all/modules/libraries/libraries.module
===================================================================
--- sites/all/modules/libraries/libraries.module (revision 12218)
+++ sites/all/modules/libraries/libraries.module (working copy)
@@ -589,8 +589,10 @@
*/
function libraries_load($name, $variant = NULL) {
$loaded = &drupal_static(__FUNCTION__, array());
+
+ $key = ($variant === NULL ? $name : $name . '.' . $variant) ;
- if (!isset($loaded[$name])) {
+ if (!isset($loaded[$key])) {
$library = cache_get($name, 'cache_libraries');
if ($library) {
$library = $library->data;
@@ -635,10 +637,10 @@
// Invoke callbacks in the 'post-load' group.
libraries_invoke('post-load', $library);
}
- $loaded[$name] = $library;
+ $loaded[$key] = $library;
}
- return $loaded[$name];
+ return $loaded[$key];
}
/**
Fixes the problem by making sure that the $loaded array has different keys for all requests to libraries_load.
Comments
Comment #1
tstoecklerSorry for not following up earlier. This currently works as designed. You can only have one variant of a library at a time. I.e. you should not be able to load both the source and the minified variant of jquery at the same time.
In case you have a single library download that contains multiple libraries, you should not use variants for that. There's #2073603: Provide support for PHP file libraries containing multiple sub-libraries for that.