Index: modules/system/system.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.api.php,v retrieving revision 1.65 diff -u -r1.65 system.api.php --- modules/system/system.api.php 26 Aug 2009 03:09:12 -0000 1.65 +++ modules/system/system.api.php 26 Aug 2009 07:48:53 -0000 @@ -365,21 +365,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', '<')) { + if (version_compare($libraries['system']['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 26 Aug 2009 07:48: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'); } } Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.975 diff -u -r1.975 common.inc --- includes/common.inc 25 Aug 2009 21:53:47 -0000 1.975 +++ includes/common.inc 26 Aug 2009 07:48:53 -0000 @@ -3234,41 +3234,52 @@ * 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() * @see hook_library_alter() - * - * @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('drupal_get_library')) { + $libraries = $cache->data; + } + else { + // Retrieve all libraries associated with each module, namespaced by the + // module name to avoid version compatibility issues. + foreach (module_implements('library') as $modulelibrary) { + $libraries[$modulelibrary] = module_invoke($modulelibrary, 'library'); + + // Add default elements to allow for easier processing. + foreach ($libraries[$modulelibrary] as $libraryname => $library) { + $libraries[$modulelibrary][$libraryname] += array( + 'dependencies' => array(), + 'js' => array(), + 'css' => array(), + ); + } + } + + // Allow modules to alter the registered libraries and save in the cache. + drupal_alter('library', $libraries); + cache_set('drupal_get_library', $libraries); + } + } + + if (isset($module) && isset($name)) { + return isset($libraries[$module][$name]) ? $libraries[$module][$name] : FALSE; } else { - $libraries[$module][$name] = FALSE; + return $libraries; } - - return $libraries[$module][$name]; } /**