Commit 5bf665ba authored by sun's avatar sun

#1023322 by tstoeckler, sun: Fixed libraries shouldn't be loaded multiple times.

parent 6de7fb32
......@@ -6,6 +6,7 @@ Libraries x.x-x.x, xxxx-xx-xx
Libraries 7.x-1.x, xxxx-xx-xx
-----------------------------
#1023322 by tstoeckler, sun: Fixed libraries shouldn't be loaded multiple times.
#1024080 by hswong3i, tstoeckler: Fixed installation profile retrieval.
#995988 by good_man: Wrong default install profile.
#975498 by Gábor Hojtsy: Update JS/CSS-loading to new drupal_add_js/css() API.
......
......@@ -343,28 +343,45 @@ function libraries_detect_library(&$library) {
* @param $name
* The name of the library to load.
* @param $variant
* The name of the variant to load.
* The name of the variant to load. Note that only one variant of a library
* can be loaded within a single request. The variant that has been passed
* first is used; different variant names in subsequent calls are ignored.
*
* @return
* An associative array of the library information as returned from
* libraries_info(). The top-level properties contain the effective definition
* of the library (variant) that has been loaded. Additionally:
* - installed: Whether the library is installed, as determined by
* libraries_detect_library().
* - loaded: Either the amount of library files that have been loaded, or
* FALSE if the library could not be loaded.
* See hook_libraries_info() for more information.
*/
function libraries_load($name, $variant = NULL) {
$library = libraries_info($name);
libraries_detect_library($library);
$loaded = &drupal_static(__FUNCTION__, array());
// If the library itself is not installed, do nothing;
if (!$library['installed']) {
return FALSE;
}
if (!isset($loaded[$name])) {
$library = libraries_info($name);
libraries_detect_library($library);
// If a variant was specified, override the top-level properties with the
// variant properties.
if (!empty($variant) && !empty($library['variants'][$variant])) {
// If the variant is not installed, do nothing.
if (!$library['variants'][$variant]['installed']) {
return FALSE;
// If a variant was specified, override the top-level properties with the
// variant properties.
if (isset($variant)) {
// Ensure that the $variant key exists, and if it does not, set its
// 'installed' property to FALSE by default. This will prevent the loading
// of the library files below.
$library['variants'] += array($variant => array('installed' => FALSE));
$library = array_merge($library, $library['variants'][$variant]);
}
// If the library (variant) is installed, load it.
$library['loaded'] = FALSE;
if ($library['installed']) {
$library['loaded'] = libraries_load_files($library);
}
$library = array_merge($library, $library['variants'][$variant]);
$loaded[$name] = $library;
}
return libraries_load_files($library, $variant);
return $loaded[$name];
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment