function protected function ApiProviderBase::parseVersions

8.x-3.x ApiProviderBase.php protected ApiProviderBase::parseVersions(array $data = [])

Parses available versions provided by the API data.

Parameters

array $data: The data to parse.

Return value

array An associative array of versions, keyed by version.

Class

ApiProviderBase
CDN Provider base that uses an API to populate its assets.

Namespace

Drupal\bootstrap\Plugin\Provider

Source src/Plugin/Provider/ApiProviderBase.php (line 278)

protected function parseVersions(array $data = []) {
  $versions = [];

  // Support APIs that have a dedicated "versions" property.
  if (!empty($data['versions'])) {
    foreach ($data['versions'] as $version) {
      // Only extract valid versions.
      if ($this->isValidVersion($version)) {
        $versions[$version] = $version;
      }
    }
  }
  // Support APIs that have the version nested under individual assets.
  elseif (!empty($data['assets'])) {
    foreach ($data['assets'] as $asset) {
      if (isset($asset['version']) && $this->isValidVersion($asset['version'])) {
        $versions[$asset['version']] = $asset['version'];
      }
    }
  }

  return $versions;
}