You are here

public static function LibrariesCdn::getCDNLibrariesVariants in Libraries CDN API 8

Same name and namespace in other branches
  1. 7 src/LibrariesCDN.php \Drupal\libraries_cdn\LibrariesCDN::getCDNLibrariesVariants()

Generate an array for the variants of the Libraries API module.

These variants are from the CDN plugins 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::getCDNLibrariesVariants()
LibrariesCdn::getLibrariesVariants in src/LibrariesCdn.php
Generate an array for the variants of the Libraries API module.

File

src/LibrariesCdn.php, line 254
Contains LibrariesCdn.

Class

LibrariesCdn
Class LibrariesCdn.

Namespace

Drupal\libraries_cdn

Code

public static function getCDNLibrariesVariants() {
  $variants = array();
  $module_path = drupal_get_path('module', 'libraries_cdn');
  $information = self::getInformation();
  $configuration = self::$plugin
    ->getConfiguration();
  $name = isset($information['name']) ? $information['name'] : self::getLibrary();
  foreach (self::getFiles() as $version => $files) {
    foreach ($files as $file) {
      if (strpos($file, 'debug') !== FALSE || strpos($file, 'min') !== FALSE) {
        continue;
      }
      $variant = self::$plugin
        ->getPluginId() . ':' . self::getLibrary() . ':' . $version;
      $ext = pathinfo($file, PATHINFO_EXTENSION);

      // Default CDN version.
      $variants[$variant]['name'] = sprintf("%s %s", $name, $version);
      $variants[$variant]['library path'] = $module_path;
      $variants[$variant]['files'][$ext][$file] = array(
        'type' => 'external',
        'data' => $file,
      ) + (array) self::$plugin
        ->getConfiguration('options');
    }
  }
  if (isset($configuration['limit']) && is_int(intval($configuration['limit'])) && $configuration['limit'] > 0) {
    $variants = array_slice($variants, 0, $configuration['limit']);
  }
  return $variants;
}