function public function ProviderBase::alterFrameworkLibrary

8.x-3.x ProviderBase.php public ProviderBase::alterFrameworkLibrary(array &$framework)
7.x-3.x ProviderBase.php public ProviderBase::alterFrameworkLibrary(array &$framework, $min = NULL)

Overrides ProviderInterface::alterFrameworkLibrary

Class

ProviderBase
CDN Provider base class.

Namespace

Drupal\bootstrap\Plugin\Provider

Source src/Plugin/Provider/ProviderBase.php (line 95)

public function alterFrameworkLibrary(array &$framework) {
  // Attempt to retrieve cached CDN assets from the database. This is
  // primarily used to avoid unnecessary API requests and speed up the
  // process during a cache rebuild. The "keyvalue.expirable" service is
  // used as it persists through cache rebuilds. In order to prevent stale
  // data, a hash is used constructed of various data relating to the CDN.
  // The cache is rebuilt if and when it has expired.
  // @see https://www.drupal.org/project/bootstrap/issues/3031415
  $data = $this->getCdnAssetsCacheData();
  $hash = Crypt::generateBase64HashIdentifier($data);

  // Retrieve the cached value or build it if necessary.
  $framework = $this->cacheGet('library', $hash, [], function() use ($framework, $data) {
    $version = isset($data['version']) ? $data['version'] : NULL;
    $theme = isset($data['theme']) ? $data['theme'] : NULL;
    $assets = $this->getCdnAssets($version, $theme)->toLibraryArray($data['min']);

    // Immediately return if there are no theme CDN assets to use.
    if (empty($assets)) {
      return $framework;
    }

    // Override the framework version with the CDN version that is being used.
    if (isset($data['version'])) {
      $framework['version'] = $data['version'];
    }

    // @todo Provide a UI setting for this?
    $styles = [];
    if ($this->theme->getSetting('cdn_styles', TRUE)) {
      $stylesProvider = ProviderManager::load($this->theme, 'drupal_bootstrap_styles');
      $styles = $stylesProvider->getCdnAssets($version, $theme)->toLibraryArray($data['min']);
    }

    // Merge the assets with the existing library info and return it.
    return NestedArray::mergeDeepArray([$assets, $styles, $framework], TRUE);
  });
}