diff --git a/libraries.api.php b/libraries.api.php index 8bf95fa..2ebb33f 100644 --- a/libraries.api.php +++ b/libraries.api.php @@ -146,9 +146,23 @@ * Valid callback groups are: * - info: Callbacks registered in this group are applied after the library * information has been retrieved via hook_libraries_info() or info files. + * At this point the following additional information is available: + * - $library['info type']: How the library information was obtained. Can + * be 'info file', 'module', or 'theme', depending on whether the + * library information was obtained from an info file, an enabled module + * or an enabled theme, respectively. + * Additionally, one of the following three keys is available, depending + * on the value of $library['info type']. + * - $library['info file']: In case the library information was obtained + * from an info file, the URI of the info file. + * - $library['module']: In case the library was obtained from an enabled + * module, the name of the providing module. + * - $library['theme']: In case the library was obtained from an enabled + * theme, the name of the providing theme. * - pre-detect: Callbacks registered in this group are applied after the * library path has been determined and before the version callback is - * invoked. At this point the following additional information is available: + * invoked. At this point the following additional information is + * available: * - $library['library path']: The path on the file system to the library. * - post-detect: Callbacks registered in this group are applied after the * library has been successfully detected. At this point the library diff --git a/libraries.module b/libraries.module index 0c7a2ce..b14ff1b 100644 --- a/libraries.module +++ b/libraries.module @@ -341,27 +341,31 @@ function &libraries_info($name = NULL) { if (!isset($libraries)) { $libraries = array(); - // Gather information from hook_libraries_info(). + + // Gather information from hook_libraries_info() in enabled modules. foreach (module_implements('libraries_info') as $module) { foreach (module_invoke($module, 'libraries_info') as $machine_name => $properties) { + $properties['info type'] = 'module'; $properties['module'] = $module; $libraries[$machine_name] = $properties; } } + // Gather information from hook_libraries_info() in enabled themes. - // @see drupal_alter() - global $theme, $base_theme_info; - if (isset($theme)) { - $theme_keys = array(); - foreach ($base_theme_info as $base) { - $theme_keys[] = $base->name; - } - $theme_keys[] = $theme; - foreach ($theme_keys as $theme_key) { - $function = $theme_key . '_' . 'libraries_info'; + $themes = array(); + foreach (list_themes() as $theme_name => $theme_info) { + if ($theme_info->status && file_exists(drupal_get_path('theme', $theme_name) . '/template.php')) { + // Collect a list of viable themes for re-use when calling the alter + // hook. + $themes[] = $theme_name; + + include_once drupal_get_path('theme', $theme_name) . '/template.php'; + + $function = $theme_name . '_libraries_info'; if (function_exists($function)) { foreach ($function() as $machine_name => $properties) { - $properties['theme'] = $theme_key; + $properties['info type'] = 'theme'; + $properties['theme'] = $theme_name; $libraries[$machine_name] = $properties; } } @@ -372,6 +376,7 @@ function &libraries_info($name = NULL) { // .info files override module definitions. foreach (libraries_scan_info_files() as $machine_name => $file) { $properties = drupal_parse_info_file($file->uri); + $properties['info type'] = 'info file'; $properties['info file'] = $file->uri; $libraries[$machine_name] = $properties; } @@ -381,8 +386,20 @@ function &libraries_info($name = NULL) { libraries_info_defaults($properties, $machine_name); } - // Allow modules to alter the registered libraries. - drupal_alter('libraries_info', $libraries); + // Allow enabled modules and themes to alter the registered libraries. + // drupal_alter() only takes the currently active theme into account, not + // all enabled themes. + foreach (module_implements('libraries_info_alter') as $module) { + $function = $module . '_libraries_info_alter'; + $function($libraries); + } + foreach ($themes as $theme) { + $function = $theme . '_libraries_info_alter'; + // The template.php file was included above. + if (function_exists($function)) { + $function($libraries); + } + } // Invoke callbacks in the 'info' group. foreach ($libraries as &$properties) {