You are here

function libraries_detect_dependencies in Libraries API 8.3

Same name and namespace in other branches
  1. 7.3 libraries.module \libraries_detect_dependencies()
  2. 7.2 libraries.module \libraries_detect_dependencies()

Library post-detect callback to process and detect dependencies.

It checks whether each of the dependencies of a library are installed and available in a compatible version.

Parameters

$library: An associative array of library information or a part of it, passed by reference.

$version: If the library information belongs to a specific version, the version string. NULL otherwise.

$variant: If the library information belongs to a specific variant, the variant name. NULL otherwise.

Deprecated

Will be removed before a stable Drupal 8 release. Please use the new library load and managment concepts described at: https://www.drupal.org/node/2170763

See also

libraries_info()

libraries_invoke()

1 call to libraries_detect_dependencies()
LibrariesWebTest::testLibrariesDetectDependencies in src/Tests/LibrariesWebTest.php
Tests libraries_detect_dependencies().
1 string reference to 'libraries_detect_dependencies'
libraries_info_defaults in ./libraries.module
Applies default properties to a library definition.

File

./libraries.module, line 346
External library handling for Drupal modules.

Code

function libraries_detect_dependencies(&$library, $version = NULL, $variant = NULL) {
  if (isset($library['dependencies'])) {
    foreach ($library['dependencies'] as &$dependency_string) {
      $dependency = Dependency::createFromString($dependency_string);
      $info = libraries_detect($dependency
        ->getName());
      if (!isset($info['installed']) || !$info['installed']) {
        $library['installed'] = FALSE;
        $library['error'] = 'missing dependency';
        $library['error message'] = t('The %dependency library, which the %library library depends on, is not installed.', [
          '%dependency' => $dependency
            ->getName(),
          '%library' => $library['name'],
        ]);
      }
      elseif (!$dependency
        ->isCompatible($info['version'])) {
        $library['installed'] = FALSE;
        $library['error'] = 'incompatible dependency';
        $library['error message'] = t('The version %dependency_version of the %dependency library is not compatible with the %library library.', [
          '%dependency_version' => $info['version'],
          '%dependency' => $info['name'],
          '%library' => $library['name'],
        ]);
      }

      // Remove the version string from the dependency, so libraries_load() can
      // load the libraries directly.
      $dependency_string = $info['name'] ?? NULL;
    }
  }
}