function libraries_get_libraries in Libraries API 8.3
Same name and namespace in other branches
- 6 libraries.module \libraries_get_libraries()
- 7.3 libraries.module \libraries_get_libraries()
- 7 libraries.module \libraries_get_libraries()
- 7.2 libraries.module \libraries_get_libraries()
Returns an array of library directories.
Returns an array of library directories from the all-sites directory (i.e. sites/all/libraries/), the profiles directory, and site-specific directory (i.e. sites/somesite/libraries/). The returned array will be keyed by the library name. Site-specific libraries are prioritized over libraries in the default directories. That is, if a library with the same name appears in both the site-wide directory and site-specific directory, only the site-specific version will be listed.
Return value
A list of library directories.
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
Related topics
1 call to libraries_get_libraries()
- libraries_get_path in ./
libraries.module - Gets the path of a library.
File
- ./
libraries.module, line 110 - External library handling for Drupal modules.
Code
function libraries_get_libraries() {
$searchdir = [];
$config = DrupalKernel::findSitePath(\Drupal::request());
// @todo core/libraries
// Similar to 'modules' and 'themes' directories inside an installation
// profile, installation profiles may want to place libraries into a
// 'libraries' directory.
if ($profile = \Drupal::installProfile()) {
$profile_path = drupal_get_path('profile', $profile);
$searchdir[] = "{$profile_path}/libraries";
}
// Search sites/all/libraries for backwards-compatibility.
$searchdir[] = 'sites/all/libraries';
// Always search the root 'libraries' directory.
$searchdir[] = 'libraries';
// Also search sites/<domain>/*.
$searchdir[] = "{$config}/libraries";
// Retrieve list of directories.
$directories = [];
$nomask = [
'CVS',
];
foreach ($searchdir as $dir) {
if (is_dir($dir) && ($handle = opendir($dir))) {
while (FALSE !== ($file = readdir($handle))) {
if (!in_array($file, $nomask) && $file[0] != '.') {
if (is_dir("{$dir}/{$file}")) {
$directories[$file] = "{$dir}/{$file}";
}
}
}
closedir($handle);
}
}
return $directories;
}