Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.930 diff -u -r1.930 common.inc --- includes/common.inc 4 Jul 2009 18:26:42 -0000 1.930 +++ includes/common.inc 4 Jul 2009 21:09:53 -0000 @@ -3027,11 +3027,12 @@ * without conflicts in case the libraries are loaded on certain pages only. * * @param $module - * The name of a module that registered a library. + * (optional) The name of a module that registered a library. * @param $library - * The name of a registered library. + * (optional) The name of a registered library. * @return - * The definition of the requested library, if existent, or FALSE. + * The definition of the requested library, if existent, or FALSE. If no + * library is requested, will return the full registry. * * @see drupal_add_library() * @see hook_library() @@ -3040,28 +3041,38 @@ * @todo The purpose of drupal_get_*() is completely different to other page * requisite API functions; find and use a different name. */ -function drupal_get_library($module, $name) { +function drupal_get_library($module = NULL, $name = NULL) { $libraries = &drupal_static(__FUNCTION__, array()); - if (!array_key_exists($module, $libraries)) { - // Retrieve all libraries associated with the module. - $module_libraries = module_invoke($module, 'library'); - - // Allow modules to alter the module's registered libraries. - if (!empty($module_libraries)) { - drupal_alter('library', $module_libraries, $module); - } - $libraries[$module] = $module_libraries; - } - if (!empty($libraries[$module][$name]) && is_array($libraries[$module][$name])) { - // Add default elements to allow for easier processing. - $libraries[$module][$name] += array('dependencies' => array(), 'js' => array(), 'css' => array()); + if (empty($libraries)) { + if ($cache = cache_get('libraries')) { + $libraries = $cache->data; + } + else { + // Retrieve all libraries associated with each module, namespaced by the + // module name to avoid version compatibility issues. + foreach (module_implements('libraries') as $module) { + $libraries[$module] = module_invoke($module, 'library'); + + // Add default elements to allow for easier processing. + $libraries[$module] += array( + 'dependencies' => array(), + 'js' => array(), + 'css' => array(), + ); + } + + // Allow modules to alter the registered libraries. + drupal_alter('library', $libraries); + } + } + + if (isset($module)) { + return isset($libraries[$module][$name]) ? $libraries[$module][$name] : FALSE; } else { - $libraries[$module][$name] = FALSE; + return $libraries; } - - return $libraries[$module][$name]; } /** Index: modules/system/system.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.api.php,v retrieving revision 1.46 diff -u -r1.46 system.api.php --- modules/system/system.api.php 4 Jul 2009 18:26:42 -0000 1.46 +++ modules/system/system.api.php 4 Jul 2009 21:09:58 -0000 @@ -266,21 +266,19 @@ * certain library also depend on the API of a certain library version. * * @param $libraries - * The JavaScript/CSS libraries provided by $module. Keyed by internal library - * name and passed by reference. - * @param $module - * The name of the module that registered the libraries. + * The registered JavaScript/CSS libraries. An array of libraries, keyed by + * the name of the module that registers the libraries. Passed by reference. * * @see hook_library() */ -function hook_library_alter(&$libraries, $module) { +function hook_library_alter(&$libraries) { // Update Farbtastic to version 2.0. - if ($module == 'system' && isset($libraries['farbtastic'])) { + if (isset($libraries['system']['farbtastic'])) { // Verify existing version is older than the one we are updating to. if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) { // Update the existing Farbtastic to version 2.0. - $libraries['farbtastic']['version'] = '2.0'; - $libraries['farbtastic']['js'] = array( + $libraries['system']['farbtastic']['version'] = '2.0'; + $libraries['system']['farbtastic']['js'] = array( drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(), ); } Index: modules/simpletest/tests/common_test.module =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common_test.module,v retrieving revision 1.2 diff -u -r1.2 common_test.module --- modules/simpletest/tests/common_test.module 4 Jul 2009 18:26:42 -0000 1.2 +++ modules/simpletest/tests/common_test.module 4 Jul 2009 21:09:53 -0000 @@ -27,12 +27,12 @@ /** * Implementation of hook_library_alter(). */ -function common_test_library_alter(&$libraries, $module) { - if ($module == 'system' && isset($libraries['farbtastic'])) { +function common_test_library_alter(&$libraries) { + if (isset($libraries['system']['farbtastic'])) { // Change the title of Farbtastic to "Farbtastic: Altered Library". - $libraries['farbtastic']['title'] = 'Farbtastic: Altered Library'; + $libraries['system']['farbtastic']['title'] = 'Farbtastic: Altered Library'; // Make Farbtastic depend on jQuery Form to test library dependencies. - $libraries['farbtastic']['dependencies'][] = array('system', 'form'); + $libraries['system']['farbtastic']['dependencies'][] = array('system', 'form'); } }