Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Asset/LibrariesDirectoryFileFinder.php \Drupal\Core\Asset\LibrariesDirectoryFileFinder::find()
  2. 9 core/lib/Drupal/Core/Asset/LibrariesDirectoryFileFinder.php \Drupal\Core\Asset\LibrariesDirectoryFileFinder::find()

Finds files that are located in the supported 'libraries' directories.

It searches the following locations:

  • A libraries directory in the current site directory, for example: sites/default/libraries.
  • The root libraries directory.
  • A libraries directory in the selected installation profile, for example: profiles/my_install_profile/libraries.

If the same library is present in multiple locations the first location found will be used. The locations are searched in the order listed.

Parameters

string $path: The path for the library file to find.

Return value

string|false The real path to the library file relative to the root directory. If the library cannot be found then FALSE.

File

core/lib/Drupal/Core/Asset/LibrariesDirectoryFileFinder.php, line 78

Class

LibrariesDirectoryFileFinder
Finds files that are located in the supported 'libraries' directories.

Namespace

Drupal\Core\Asset

Code

public function find($path) {

  // Search sites/<domain>/*.
  $directories[] = "{$this->sitePath}/libraries/";

  // Always search the root 'libraries' directory.
  $directories[] = 'libraries/';

  // Installation profiles can place libraries into a 'libraries' directory.
  if ($this->installProfile) {
    $profile_path = $this->profileExtensionList
      ->getPath($this->installProfile);
    $directories[] = "{$profile_path}/libraries/";
  }
  foreach ($directories as $dir) {
    if (file_exists($this->root . '/' . $dir . $path)) {
      return $dir . $path;
    }
  }

  // The library has not been found.
  return FALSE;
}