You are here

function advagg_css_alter in Advanced CSS/JS Aggregation 8.2

Same name and namespace in other branches
  1. 8.4 advagg.module \advagg_css_alter()
  2. 8.3 advagg.module \advagg_css_alter()
  3. 7.2 advagg_font/advagg_font.module \advagg_css_alter()

Implements hook_css_alter().

File

./advagg.module, line 235
Advanced CSS/JS aggregation module.

Code

function advagg_css_alter(&$css) {
  if (!advagg_enabled()) {
    return;
  }
  if (\Drupal::config('advagg.settings')
    ->get('css.fix_type')) {

    // Fix type if it was incorrectly set.
    foreach ($css as &$value) {
      if (empty($value['data']) || !is_string($value['data'])) {
        continue;
      }

      // Default to file if not set.
      if ($value['type'] !== 'file' && $value['type'] !== 'external') {
        $value['type'] = 'file';
      }

      // If type is external but doesn't start with http, https, or // change it
      // to file.
      if ($value['type'] === 'external' && stripos($value['data'], 'http://') !== 0 && stripos($value['data'], 'https://') !== 0 && stripos($value['data'], '//') !== 0) {
        $value['type'] = 'file';
      }

      // If type is file but it starts with http, https, or // change it to
      // external.
      if ($value['type'] === 'file' && (stripos($value['data'], 'http://') === 0 || stripos($value['data'], 'https://') === 0 || stripos($value['data'], '//') === 0 && stripos($value['data'], '///') === FALSE)) {
        $value['type'] = 'external';
      }
    }
    unset($value);
  }
}