Same name in other branches
  1. 6.0.x src/Asset/AssetOptimizer.php \Drupal\advagg\Asset\AssetOptimizer::processAssetArray()
  2. 8.x-3.x src/Asset/AssetOptimizer.php \Drupal\advagg\Asset\AssetOptimizer::processAssetArray()
  3. 8.x-4.x src/Asset/AssetOptimizer.php \Drupal\advagg\Asset\AssetOptimizer::processAssetArray()

Process a core asset array.

Paramètres

array $assets: The core asset array (css or js) to process.

Fichier

src/Asset/AssetOptimizer.php, line 151

Classe

AssetOptimizer
Defines the base AdvAgg optimizer.

Namespace

Drupal\advagg\Asset

Code

public function processAssetArray(array &$assets) {
    $protocol_relative = $this->config
        ->get('path.convert.absolute_to_protocol_relative');
    $force_https = $this->config
        ->get('path.convert.force_https');
    foreach ($assets as &$asset) {
        if (!is_string($asset['data'])) {
            continue;
        }
        // Fix type if it was incorrectly set.
        if ($this->fixType) {
            $this->fixType($asset);
        }
        if ($asset['type'] === 'file' && $asset['preprocess']) {
            if (!is_readable($asset['data'])) {
                continue;
            }
            $this->scanFile($asset);
        }
        elseif ($asset['type'] === 'external') {
            if ($force_https) {
                $asset['data'] = $this->convertPathForceHttps($asset['data']);
            }
            elseif ($protocol_relative) {
                $asset['data'] = $this->convertPathProtocolRelative($asset['data']);
            }
            $scheme = parse_url($asset['data'], PHP_URL_SCHEME);
            $host = parse_url($asset['data'], PHP_URL_HOST);
            $asset_url = isset($scheme) ? "{$scheme}://{$host}" : "//{$host}";
            $this->dnsPrefetch[] = $asset_url;
        }
    }
    if (!isset($GLOBALS['_advagg_prefetch'])) {
        $GLOBALS['_advagg_prefetch'] = [];
    }
    $GLOBALS['_advagg_prefetch'] += $this->dnsPrefetch;
}