Commit ce7fefdb authored by alexpott's avatar alexpott

Issue #2228745 by Wim Leers, sqndr, nod_, undertext: Fixed Color module...

Issue #2228745 by Wim Leers, sqndr, nod_, undertext: Fixed Color module doesn't look for CSS files declared in a library.
parent e5921e78
......@@ -93,6 +93,36 @@ function color_css_alter(&$css) {
}
}
/**
* Implements hook_library_alter().
*
* Replaces style sheets declared in libraries with color-altered style sheets.
*/
function color_library_alter(&$library, $name) {
$active_theme = \Drupal::theme()->getActiveTheme();
$theme_key = $active_theme->getName();
$theme_libraries = $active_theme->getLibraries();
if (in_array($name, $theme_libraries)) {
// Override stylesheets.
$color_paths = \Drupal::config('color.theme.' . $theme_key)->get('stylesheets');
if (!empty($color_paths)) {
foreach ($library['css'] as &$css) {
// Loop over the path array with recolored CSS files to find matching
// paths which could replace the non-recolored paths.
foreach ($color_paths as $color_path) {
// Color module currently requires unique file names to be used,
// which allows us to compare different file paths.
if (drupal_basename($css['data']) == drupal_basename($color_path)) {
// Replace the path to the new css file.
// This keeps the order of the stylesheets intact.
$css['data'] = $color_path;
}
}
}
}
}
}
/**
* Implements hook_preprocess_page().
*
......
......@@ -66,7 +66,7 @@ protected function setUp() {
),
'color_test_theme' => array(
'palette_input' => 'palette[bg]',
'scheme' => '',
'scheme' => 'custom',
'scheme_color' => '#3b3b3b',
),
);
......
......@@ -8,13 +8,25 @@
$info = array(
'fields' => array(
'bg' => t('Main background'),
'text' => t('Text color'),
),
'schemes' => array(
'default' => array(
'title' => t('Default'),
'colors' => array(
'bg' => '#ff0000',
'text' => '#0000ff',
),
),
'custom' => array(
'title' => t('Custom'),
'colors' => array(
'bg' => '#ff0000',
'text' => '#3b3b3b',
),
),
),
'css' => array(
'css/colors.css',
),
);
......@@ -3,3 +3,5 @@ type: theme
description: 'Theme for testing the color module'
version: VERSION
core: 8.x
libraries:
- color_test_theme/base
......@@ -4,17 +4,8 @@ description: 'A flexible, recolorable theme with many regions and a responsive,
package: Core
version: VERSION
core: 8.x
# @todo use library version once color module is fixed #2228745
#libraries:
# - bartik/base
#
stylesheets:
all:
- css/layout.css
- css/style.css
- css/colors.css
print:
- css/print.css
libraries:
- bartik/base
ckeditor_stylesheets:
- css/ckeditor-iframe.css
regions:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment