You are here

function _navbar_convert_libraries_to_library in Navbar 7

Converts a libraries module array to a hook_library array.

@todo Libraries API should automatically register all libraries in hook_library(). See https://drupal.org/node/1386368

Return value

Array Returns a standard Drupal library definition structure.

1 call to _navbar_convert_libraries_to_library()
navbar_library in ./navbar.module
Implements hook_library().

File

./navbar.module, line 1120
Administration navbar for quick access to top level administration items.

Code

function _navbar_convert_libraries_to_library($library, $options = array()) {

  // If the library wasn't installed, don't bother converting it.
  if (!$library['installed']) {
    return array();
  }
  $converted = array();
  $files = array();

  // Get the library files from one of the installed variants.
  if ($name = _navbar_libraries_get_preferred_variant_name($library)) {
    $files = $library['variants'][$name]['files'];
  }

  // Define the library if files exist for it.
  if (!empty($files)) {

    // This is the basic structure expected by hook_library().
    $converted = array(
      'title' => $library['name'],
      'website' => $library['vendor url'],
      'version' => $library['version'],
    );
    foreach ($files as $type => $paths) {
      foreach ($paths as $filename => $data) {
        $converted[$type][$library['library path'] . '/' . $filename] = $options;
      }
    }
  }
  return $converted;
}