diff --git a/core/includes/common.inc b/core/includes/common.inc index 1176202..f182416 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2736,16 +2736,16 @@ function drupal_add_library($module, $name, $every_page = NULL) { * - Two (or more) modules can still register the same library and use it * without conflicts in case the libraries are loaded on certain pages only. * - * @param $module - * The name of a module that registered a library. + * @param $extension + * The name of the extension that registered a library. * @param $name * (optional) The name of a registered library to retrieve. By default, all - * libraries registered by $module are returned. + * libraries registered by $extension are returned. * * @return * The definition of the requested library, if $name was passed and it exists, * or FALSE if it does not exist. If no $name was passed, an associative array - * of libraries registered by $module is returned (which may be empty). + * of libraries registered by $extension is returned (which may be empty). * * @see drupal_add_library() * @see hook_library_info_alter() @@ -2753,38 +2753,37 @@ function drupal_add_library($module, $name, $every_page = NULL) { * @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 = NULL) { - static $library_info = array(); +function drupal_get_library($extension, $name = NULL) { $libraries = &drupal_static(__FUNCTION__, array()); - if ($module === 'core') { - $module_path = 'core'; - $library_file = 'core/core.library.yml'; - } - else { - // @todo Add a $type argument OR automatically figure out the type based on - // current extension data, possibly using a module->theme fallback mechanism. - $module_path = drupal_get_path('module', $module); - if (in_array($module, array('seven', 'bartik'))) { - $module_path = drupal_get_path('theme', $module); - } - $library_file = $module_path . '/' . $module . '.library.yml'; + if (!isset($libraries[$extension]) && ($cache = cache()->get('library_info:' . $extension))) { + $libraries[$extension] = $cache->data; } - if (!isset($libraries[$module])) { - if (!isset($library_info[$module])) { - $library_info[$module] = array(); - if (file_exists($library_file)) { - $parser = new Parser(); - $library_info[$module] = $parser->parse(file_get_contents($library_file)) ?: array(); + if (!isset($libraries[$extension])) { + $libraries[$extension] = array(); + if ($extension === 'core') { + $path = 'core'; + } + else { + // @todo Add a $type argument OR automatically figure out the type based on + // current extension data, possibly using a module->theme fallback mechanism. + $path = drupal_get_path('module', $extension); + if (!$path) { + $path = drupal_get_path('theme', $extension); } } - $module_libraries = $library_info[$module]; + $library_file = DRUPAL_ROOT . '/' . $path . '/' . $extension . '.library.yml'; + + if ($library_file && file_exists($library_file)) { + $parser = new Parser(); + $libraries[$extension] = $parser->parse(file_get_contents($library_file)) ?: array(); - // Allow modules to alter the module's registered libraries. - drupal_alter('library_info', $module_libraries, $module); + // Allow modules to alter the module's registered libraries. + drupal_alter('library_info', $libraries[$extension], $extension); + } - foreach ($module_libraries as $id => $library) { + foreach ($libraries[$extension] as $id => &$library) { $library += array('dependencies' => array(), 'js' => array(), 'css' => array()); if (isset($library['version'])) { @@ -2807,12 +2806,19 @@ function drupal_get_library($module, $name = NULL) { if (isset($options['file'])) { $options['type'] = 'file'; - // An absolute path maps to DRUPAL_ROOT. - if ($options['file'][0] === '/' && $options['file'][1] !== '/') { - $options['data'] = substr($options['file'], 1); + if ($options['file'][0] === '/') { + // An absolute path maps to DRUPAL_ROOT. + if ($options['file'][1] !== '/') { + $options['data'] = substr($options['file'], 1); + } + // A protocol-free URI is external. + else { + $options['data'] = $options['file']; + $options['type'] = 'external'; + } } else { - $options['data'] = $module_path . '/' . $options['file']; + $options['data'] = $path . '/' . $options['file']; } unset($options['file']); $options['version'] = $library['version']; @@ -2839,17 +2845,17 @@ function drupal_get_library($module, $name = NULL) { $library['dependencies'][$i] = explode('/', $dependency, 2); } } - $module_libraries[$id] = $library; } - $libraries[$module] = $module_libraries; + cache()->set('library_info:' . $extension, $libraries[$extension], CacheBackendInterface::CACHE_PERMANENT, array('library_info')); } + if (isset($name)) { - if (!isset($libraries[$module][$name])) { - $libraries[$module][$name] = FALSE; + if (!isset($libraries[$extension][$name])) { + $libraries[$extension][$name] = FALSE; } - return $libraries[$module][$name]; + return $libraries[$extension][$name]; } - return $libraries[$module]; + return $libraries[$extension]; } /** diff --git a/core/includes/module.inc b/core/includes/module.inc index 429f5db..3062202 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -112,6 +112,13 @@ function system_list_reset() { drupal_static_reset('list_themes'); cache('bootstrap')->delete('system_list'); cache()->delete('system_info'); + + // Clear the library info cache. + // Libraries may be provided by all extension types, and may be altered by any + // other extensions (types) due to the nature of drupal_alter() and the fact + // that profiles are recorded and handled as modules. + cache()->invalidateTags(array('library_info')); + // Remove last known theme data state. // This causes system_list() to call system_rebuild_theme_data() on its next // invocation. When enabling a module that implements hook_system_info_alter()