You are here

function libraries_info in Libraries API 7.3

Same name and namespace in other branches
  1. 8.3 libraries.module \libraries_info()
  2. 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.

See also

hook_libraries_info()

4 calls to libraries_info()
LibrariesTestCase::testCallbacks in tests/libraries.test
Tests the applying of callbacks.
LibrariesTestCase::testLibrariesInfo in tests/libraries.test
Tests libraries_info().
libraries_detect in ./libraries.module
Tries to detect a library and its installed version.
libraries_drush_list in ./libraries.drush.inc
Lists registered library information.
1 string reference to 'libraries_info'
libraries_flush_caches in ./libraries.module
Implements hook_flush_caches().

File

./libraries.module, line 391
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 = array();

    // 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. Themes
    // are sorted to ensure that a base theme's template.php is included before
    // its children's ones.
    $themes = array();
    foreach (libraries_get_enabled_themes() as $theme_name => $theme_info) {
      if (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['info type'] = 'theme';
            $properties['theme'] = $theme_name;
            $libraries[$machine_name] = $properties;
          }
        }
      }
    }

    // Gather information from .info files.
    // .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;
    }

    // Provide defaults.
    foreach ($libraries as $machine_name => &$properties) {
      libraries_info_defaults($properties, $machine_name);
    }

    // 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) {
      libraries_invoke('info', $properties);
    }
  }
  if (isset($name)) {
    if (!empty($libraries[$name])) {
      return $libraries[$name];
    }
    else {
      $false = FALSE;
      return $false;
    }
  }
  return $libraries;
}