drupal_get_library
- Versions
- 7
drupal_get_library($module, $name)
Retrieves information for a JavaScript/CSS library.
Library information is statically cached. Libraries are keyed by module for several reasons:
- Libraries are not unique. Multiple modules might ship with the same library in a different version or variant. This registry cannot (and does not attempt to) prevent library conflicts.
- Modules implementing and thereby depending on a library that is registered by another module can only rely on that module's library.
- 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.
See also
@see hook_library()
See also
@todo The purpose of drupal_get_*() is completely different to other page requisite API functions; find and use a different name.
Parameters
$module The name of a module that registered a library.
$library The name of a registered library.
Return value
The definition of the requested library, if existent, or FALSE.
Code
includes/common.inc, line 4166
<?php
function drupal_get_library($module, $name) {
$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());
}
else {
$libraries[$module][$name] = FALSE;
}
return $libraries[$module][$name];
}
?>Login or register to post comments 