public static function LibrariesCdn::getLocalLibrariesVariants in Libraries CDN API 8
Same name and namespace in other branches
- 7 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.
Return value
array The returned array can be applied to the 'variants' key in the library definition in hook_libraries_info().
1 call to LibrariesCdn::getLocalLibrariesVariants()
- LibrariesCdn::getLibrariesVariants in src/
LibrariesCdn.php - Generate an array for the variants of the Libraries API module.
File
- src/
LibrariesCdn.php, line 297 - Contains LibrariesCdn.
Class
- LibrariesCdn
- Class LibrariesCdn.
Namespace
Drupal\libraries_cdnCode
public static function getLocalLibrariesVariants() {
$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($options['download'])) {
$variant = 'local:' . self::$plugin
->getPluginId() . ':' . self::getLibrary() . ':' . $version;
if (isset($options['download']['versions'])) {
$versions = array_map(function ($version) {
if ($version === 'latest') {
return self::$plugin
->getLatestVersion();
}
else {
return $version;
}
}, (array) $options['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($options['download']['plugins'])) {
$options['download']['plugins'] = (array) $options['download']['plugins'];
foreach ($options['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;
}