You are here

protected function CssOptimizer::fixType in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::fixType()

Checks for and if found fixes incorrectly set asset types.

Parameters

array $asset: A core single asset definition array.

Overrides AssetOptimizer::fixType

File

src/Asset/CssOptimizer.php, line 47

Class

CssOptimizer
The CSS Optimizer.

Namespace

Drupal\advagg\Asset

Code

protected function fixType(array &$asset) {

  // Default asset type to file if not set/invalid.
  if (!in_array($asset['type'], [
    'file',
    'external',
    'settings',
  ])) {
    $asset['type'] = 'file';
  }
  $path = $asset['data'];
  if ($asset['type'] === 'external') {

    // If type is external but path doesn't start with http, https, or //
    // change it to file.
    if (stripos($path, 'http') !== 0 && stripos($path, '//') !== 0) {
      $asset['type'] = 'file';
    }
    elseif (stripos($path, $this->basePath) !== FALSE && !$this->config
      ->get('css.preserve_external')) {
      $asset['type'] = 'file';
      $asset['group'] = CSS_BASE;
      $asset['every_page'] = TRUE;
      $asset['weight'] = -40000;
      $asset['data'] = substr($asset['data'], stripos($asset['data'], $this->basePath) + $this->basePathLen);
    }
  }
  elseif ($asset['type'] === 'file' && (stripos($path, 'http') === 0 || stripos($path, '//') === 0)) {
    $asset['type'] = 'external';
  }
}