function conditional_styles_css_alter in Conditional Stylesheets 8
Implements hook_css_alter().
File
- ./
conditional_styles.module, line 13 - Adds conditional CSS from the .info file.
Code
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,
],
];
}
}
}
}