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

drupal_add_library()

@see hook_library()

See also

hook_library_alter()

@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
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.