conditional_styles.module in Conditional Stylesheets 8
Same filename and directory in other branches
Adds conditional CSS from the .info file.
File
conditional_styles.moduleView source
<?php
/**
* @file
* Adds conditional CSS from the .info file.
*/
use Drupal\Component\Utility\Unicode;
/**
* Implements hook_css_alter().
*/
function conditional_styles_css_alter(&$css, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
$theme_handler = \Drupal::service('theme_handler');
$current_theme = $theme_handler
->getDefault();
$path = drupal_get_path('theme', $current_theme);
$info = $theme_handler
->getTheme($current_theme)->info;
if (!empty($info['conditional-stylesheets'])) {
foreach ($info['conditional-stylesheets'] as $version => $media) {
foreach ($media as $key => $file_path) {
$full_path = "{$path}/{$file_path}";
$css[$full_path] = [
'group' => CSS_THEME,
'weight' => 999,
'type' => 'file',
'preprocess' => TRUE,
'data' => $full_path,
'media' => $key,
'every_page' => TRUE,
'browsers' => [
'IE' => $version,
'!IE' => Unicode::strpos($version, '!IE') !== FALSE,
],
];
}
}
}
}
Functions
Name | Description |
---|---|
conditional_styles_css_alter | Implements hook_css_alter(). |