You are here

function LibrariesLoad::librariesLoad in X Autoload 7.5

Parameters

string $name:

See also

libraries_load()

File

tests/src/VirtualDrupal/LibrariesLoad.php, line 40

Class

LibrariesLoad

Namespace

Drupal\xautoload\Tests\VirtualDrupal

Code

function librariesLoad($name) {
  $loaded =& $this->drupalStatic
    ->get('libraries_load', array());
  if (!isset($loaded[$name])) {
    $library = $this->cache
      ->cacheGet($name, 'cache_libraries');
    if ($library) {
      $library = $library->data;
    }
    else {
      $library = $this
        ->librariesDetect($name);
      $this->cache
        ->cacheSet($name, $library, 'cache_libraries');
    }

    // If a variant was specified, override the top-level properties with the
    // variant properties.
    if (isset($variant)) {

      // Ensure that the $variant key exists, and if it does not, set its
      // 'installed' property to FALSE by default. This will prevent the loading
      // of the library files below.
      $library['variants'] += array(
        $variant => array(
          'installed' => FALSE,
        ),
      );
      $library = array_merge($library, $library['variants'][$variant]);
    }

    // Regardless of whether a specific variant was requested or not, there can
    // only be one variant of a library within a single request.
    unset($library['variants']);

    // Invoke callbacks in the 'pre-dependencies-load' group.
    $this
      ->librariesInvoke('pre-dependencies-load', $library);

    // If the library (variant) is installed, load it.
    $library['loaded'] = FALSE;
    if ($library['installed']) {

      // Load library dependencies.
      if (isset($library['dependencies'])) {
        foreach ($library['dependencies'] as $dependency) {
          $this
            ->librariesLoad($dependency);
        }
      }

      // Invoke callbacks in the 'pre-load' group.
      $this
        ->librariesInvoke('pre-load', $library);

      // Load all the files associated with the library.
      $library['loaded'] = $this
        ->librariesLoadFiles($library);

      // Invoke callbacks in the 'post-load' group.
      $this
        ->librariesInvoke('post-load', $library);
    }
    $loaded[$name] = $library;
  }
  return $loaded[$name];
}