function libraries_info in Libraries API 8.3
Same name and namespace in other branches
- 7.3 libraries.module \libraries_info()
- 7.2 libraries.module \libraries_info()
Returns information about registered libraries.
The returned information is unprocessed; i.e., as registered by modules.
@todo Re-introduce support for include file plugin system - either by copying Wysiwyg's code, or directly switching to CTools.
Parameters
$name: (optional) The machine name of a library to return registered information for. If omitted, information about all registered libraries is returned.
Return value
array|false An associative array containing registered information for all libraries, the registered information for the library specified by $name, or FALSE if the library $name is not registered.
Deprecated
Will be removed before a stable Drupal 8 release. Please use the new library load and managment concepts described at: https://www.drupal.org/node/2170763
See also
3 calls to libraries_info()
- LibrariesWebTest::testCallbacks in src/
Tests/ LibrariesWebTest.php - Tests the applying of callbacks.
- LibrariesWebTest::testLibrariesInfo in src/
Tests/ LibrariesWebTest.php - Tests libraries_info().
- libraries_detect in ./
libraries.module - Tries to detect a library and its installed version.
File
- ./
libraries.module, line 399 - External library handling for Drupal modules.
Code
function &libraries_info($name = NULL) {
// This static cache is re-used by libraries_detect() to save memory.
$libraries =& drupal_static(__FUNCTION__);
if (!isset($libraries)) {
$libraries = [];
// Gather information from hook_libraries_info().
$module_handler = \Drupal::moduleHandler();
foreach ($module_handler
->getImplementations('libraries_info') as $module) {
foreach ($module_handler
->invoke($module, 'libraries_info') as $machine_name => $properties) {
$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 = [];
foreach ($base_theme_info as $base) {
$theme_keys[] = $base->name;
}
$theme_keys[] = $theme;
foreach ($theme_keys as $theme_key) {
$function = $theme_key . '_libraries_info';
if (function_exists($function)) {
foreach ($function() as $machine_name => $properties) {
$properties['theme'] = $theme_key;
$libraries[$machine_name] = $properties;
}
}
}
}
// Gather information from .info files.
// .info files override module definitions.
// In order to stop Drupal's extension and the Drupal.org packaging
// system from finding library info files we use the 'libraries.info.yml'
// file extension. Therefore, having a 'type' key, like info files of
// modules, themes, and profiles have, is superfluous.
// \Drupal\Core\Extension\InfoParser, however, enforces the existence of a
// 'type' key in info files. We therefore use Symfony's YAML parser
// directly.
// @todo Consider creating a dedicating InfoParser for library info files
// similar to \Drupal\Core\Extension\InfoParser.
$parser = new Parser();
foreach (libraries_scan_info_files() as $machine_name => $file) {
$properties = $parser
->parse(file_get_contents($file->uri));
$properties['info file'] = $file->uri;
$libraries[$machine_name] = $properties;
}
// Provide defaults.
foreach ($libraries as $machine_name => &$properties) {
libraries_info_defaults($properties, $machine_name);
}
// Allow modules to alter the registered libraries.
$module_handler
->alter('libraries_info', $libraries);
// Invoke callbacks in the 'info' group.
foreach ($libraries as &$properties) {
libraries_invoke('info', $properties);
}
}
if (isset($name)) {
if (!empty($libraries[$name])) {
return $libraries[$name];
}
else {
$false = FALSE;
return $false;
}
}
return $libraries;
}