public static function LibrariesCDN::getLocalLibrariesVariants in Libraries CDN API 7
Same name and namespace in other branches
- 8 src/LibrariesCdn.php \Drupal\libraries_cdn\LibrariesCdn::getLocalLibrariesVariants()
Generate an array for the variants of the Libraries API module.
These variants are from the local installation only.
Parameters
array $library: The library array.
Return value
array The returned array can be applied to the 'variants' key in the library definition in hook_libraries_info().
2 calls to LibrariesCDN::getLocalLibrariesVariants()
- LibrariesCDN::getLibrariesVariants in src/
LibrariesCDN.php - Generate an array for the variants of the Libraries API module.
- libraries_cdn_cron in ./
libraries_cdn.module - Implements hook_cron().
File
- src/
LibrariesCDN.php, line 305 - Contains LibrariesCDN.
Class
- LibrariesCDN
- Class LibrariesCDN.
Namespace
Drupal\libraries_cdnCode
public static function getLocalLibrariesVariants(array &$library = array()) {
$variants = array();
$information = self::getInformation();
$name = isset($information['name']) ? $information['name'] : self::getLibrary();
foreach (self::getFiles() as $version => $files) {
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if (strpos($file, 'debug') !== FALSE || strpos($file, 'min') !== FALSE) {
continue;
}
if (isset($library['cdn']['download'])) {
$variant = 'local:' . self::$plugin
->getPluginId() . ':' . self::getLibrary() . ':' . $version;
if (isset($library['cdn']['download']['versions'])) {
$versions = array_map(function ($version) {
if ($version === 'latest') {
return self::$plugin
->getLatestVersion();
}
else {
return $version;
}
}, (array) $library['cdn']['download']['versions']);
if (in_array($version, $versions)) {
self::$plugin
->getLocalCopy(array(
$version,
));
$file = self::$plugin
->getLocalFileName($file, $version);
$variants[$variant]['name'] = sprintf("%s %s (cloned from %s)", $name, $version, self::$plugin
->getPluginId());
$variants[$variant]['library path'] = self::$plugin
->getLocalDirectoryName($version);
$variants[$variant]['files'][$ext][$file] = array(
'type' => 'file',
'data' => $file,
) + (array) self::$plugin
->getConfiguration('options');
}
}
if (isset($library['cdn']['download']['plugins'])) {
$options['download']['plugins'] = (array) $library['cdn']['download']['plugins'];
foreach ($library['cdn']['download']['plugins'] as $plugin => $versions) {
$versions = array_map(function ($version) {
if ($version === 'latest') {
return self::$plugin
->getLatestVersion();
}
else {
return $version;
}
}, $versions);
if (($plugin == self::$plugin
->getPluginId() || $plugin == '*') && in_array($version, $versions)) {
self::$plugin
->getLocalCopy(array(
$version,
));
$file = self::$plugin
->getLocalFileName($file, $version);
$variants[$variant]['name'] = sprintf("%s %s (cloned from %s)", $name, $version, self::$plugin
->getPluginId());
$variants[$variant]['library path'] = self::$plugin
->getLocalDirectoryName($version);
$variants[$variant]['files'][$ext][$file] = array(
'type' => 'file',
'data' => $file,
) + (array) self::$plugin
->getConfiguration('options');
}
}
}
}
}
}
return $variants;
}