You are here

link_css.module in Link CSS 8

Same filename and directory in other branches
  1. 7 link_css.module

Link CSS Module.

Include CSS files using <link> element instead of @import. This is useful for live refresh workflows such as CodeKit which do not support files loaded with @import.

File

link_css.module
View source
<?php

/**
 * @file
 * Link CSS Module.
 *
 * Include CSS files using <link> element instead of @import. This is useful for
 * live refresh workflows such as CodeKit which do not support files loaded with
 * @import.
 */

/**
 * Implements hook_css_alter().
 */
function link_css_css_alter(&$css) {
  $system_css_preprocess = \Drupal::config('system.performance')
    ->get('css.preprocess');
  $config = \Drupal::config('link_css.settings');
  $count = 0;
  if (!$system_css_preprocess) {
    foreach ($css as $key => $value) {

      // Skip core files.
      $is_core = strpos($value['data'], 'misc/') === 0 || strpos($value['data'], 'modules/') === 0;
      if (!$config
        ->get('link_css_skip_system') || !$is_core) {

        // This option forces embeding with a link element.
        $css[$key]['preprocess'] = FALSE;
        $count++;
      }
    }

    // Show IE warning.
    if ($config
      ->get('link_css_warn_ie_limit') && $count > 31) {
      drupal_set_message(t('Internet Explorer <=7 which will not load more than 31
        linked stylesheets. The current page links to @count. Disable Link CSS
        module or turn on CSS aggregation to ensure compatibility.', array(
        '@count' => $count,
      )), 'warning');
    }
  }
}

Functions

Namesort descending Description
link_css_css_alter Implements hook_css_alter().