diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 249f6f12b3b5490799d1a5b90bd0537a049ee439..4aa5b74f0914f8014625c115755f5be9d046d52c 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -114,6 +114,22 @@ function color_get_info($theme) { $file = DRUPAL_ROOT . '/' . $path . '/color/color.inc'; if ($path && file_exists($file)) { include $file; + // Add in default values. + $info += array( + // CSS files (excluding @import) to rewrite with new color scheme. + 'css' => array(), + // Files to copy. + 'copy' => array(), + // Gradient definitions. + 'gradients' => array(), + // Color areas to fill (x, y, width, height). + 'fill' => array(), + // Coordinates of all the theme slices (x, y, width, height) with their + // filename as used in the stylesheet. + 'slices' => array(), + // Reference color used for blending. + 'blend_target' => '#ffffff', + ); $theme_info[$theme] = $info; return $info; } @@ -245,9 +261,11 @@ function template_preprocess_color_scheme_form(&$variables) { $info = $form['info']['#value']; $path = drupal_get_path('theme', $theme) . '/'; - $preview_css_path = $path . $info['preview_css']; + if (isset($info['preview_css'])) { + $preview_css_path = $path . $info['preview_css']; + $form['scheme']['#attached']['css'][$preview_css_path] = array(); + } $preview_js_path = isset($info['preview_js']) ? $path . $info['preview_js'] : drupal_get_path('module', 'color') . '/' . 'preview.js'; - $form['scheme']['#attached']['css'][$preview_css_path] = array(); // Add the JS at a weight below color.js. $form['scheme']['#attached']['js'][$preview_js_path] = array('weight' => -1); @@ -344,23 +362,25 @@ function color_scheme_form_submit($form, &$form_state) { } // Make sure enough memory is available. - // Fetch source image dimensions. - $source = drupal_get_path('theme', $theme) . '/' . $info['base_image']; - list($width, $height) = getimagesize($source); - - // We need at least a copy of the source and a target buffer of the same - // size (both at 32bpp). - $required = $width * $height * 8; - // We intend to prevent color scheme changes if there isn't enough memory - // available. memory_get_usage(TRUE) returns a more accurate number than - // memory_get_usage(), therefore we won't inadvertently reject a color - // scheme change based on a faulty memory calculation. - $usage = memory_get_usage(TRUE); - $memory_limit = ini_get('memory_limit'); - $size = parse_size($memory_limit); - if (!drupal_check_memory_limit($usage + $required, $memory_limit)) { - drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_size($usage + $required - $size), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error'); - return; + if (isset($info['base_image'])) { + // Fetch source image dimensions. + $source = drupal_get_path('theme', $theme) . '/' . $info['base_image']; + list($width, $height) = getimagesize($source); + + // We need at least a copy of the source and a target buffer of the same + // size (both at 32bpp). + $required = $width * $height * 8; + // We intend to prevent color scheme changes if there isn't enough memory + // available. memory_get_usage(TRUE) returns a more accurate number than + // memory_get_usage(), therefore we won't inadvertently reject a color + // scheme change based on a faulty memory calculation. + $usage = memory_get_usage(TRUE); + $memory_limit = ini_get('memory_limit'); + $size = parse_size($memory_limit); + if (!drupal_check_memory_limit($usage + $required, $memory_limit)) { + drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_size($usage + $required - $size), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error'); + return; + } } // Delete old files. @@ -408,7 +428,7 @@ function color_scheme_form_submit($form, &$form_state) { } // Render new images, if image has been provided. - if ($info['base_image']) { + if (isset($info['base_image'])) { _color_render_images($theme, $info, $paths, $palette); } diff --git a/core/modules/color/lib/Drupal/color/Tests/ColorTest.php b/core/modules/color/lib/Drupal/color/Tests/ColorTest.php index a22b003881a0e06ae3cfb5d08a3b050d32140e48..2e14d685fa17b9e00a02fd234a5b4ed6defc6b89 100644 --- a/core/modules/color/lib/Drupal/color/Tests/ColorTest.php +++ b/core/modules/color/lib/Drupal/color/Tests/ColorTest.php @@ -19,7 +19,7 @@ class ColorTest extends WebTestBase { * * @var array */ - public static $modules = array('color'); + public static $modules = array('color', 'color_test'); protected $big_user; protected $themes; @@ -46,6 +46,11 @@ function setUp() { 'scheme' => 'slate', 'scheme_color' => '#3b3b3b', ), + 'color_test_theme' => array( + 'palette_input' => 'palette[bg]', + 'scheme' => '', + 'scheme_color' => '#3b3b3b', + ), ); theme_enable(array_keys($this->themes)); @@ -90,10 +95,12 @@ function _testColor($theme, $test_values) { $this->drupalGet('<front>'); $stylesheets = \Drupal::config('color.' . $theme)->get('stylesheets'); - $this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')'); + foreach ($stylesheets as $stylesheet) { + $this->assertPattern('|' . file_create_url($stylesheet) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')'); + $stylesheet_content = join("\n", file($stylesheet)); + $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')'); + } - $stylesheet_content = join("\n", file($stylesheets[0])); - $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')'); $this->drupalGet($settings_path); $this->assertResponse(200); @@ -102,8 +109,10 @@ function _testColor($theme, $test_values) { $this->drupalGet('<front>'); $stylesheets = \Drupal::config('color.' . $theme)->get('stylesheets'); - $stylesheet_content = join("\n", file($stylesheets[0])); - $this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')'); + foreach ($stylesheets as $stylesheet) { + $stylesheet_content = join("\n", file($stylesheet)); + $this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')'); + } // Test with aggregated CSS turned on. $config = \Drupal::config('system.performance'); diff --git a/core/modules/color/tests/modules/color_test/color_test.info.yml b/core/modules/color/tests/modules/color_test/color_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..7b31befb69c63f1e2284ca66456ddc115bbcfaf0 --- /dev/null +++ b/core/modules/color/tests/modules/color_test/color_test.info.yml @@ -0,0 +1,7 @@ +name: 'Color test' +type: module +description: 'Provides test helpers for color module.' +package: Testing +version: VERSION +core: 8.x +hidden: true diff --git a/core/modules/color/tests/modules/color_test/color_test.module b/core/modules/color/tests/modules/color_test/color_test.module new file mode 100644 index 0000000000000000000000000000000000000000..603906ee423edfc976566256447d7f026ec5fe32 --- /dev/null +++ b/core/modules/color/tests/modules/color_test/color_test.module @@ -0,0 +1,14 @@ +<?php + +/** + * @file + * Provide test color module. + */ + +/** + * Implements hook_system_theme_info(). + */ +function color_test_system_theme_info() { + $themes['color_test_theme'] = drupal_get_path('module', 'color_test') . '/themes/color_test_theme/color_test_theme.info.yml'; + return $themes; +} diff --git a/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/color.inc b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/color.inc new file mode 100644 index 0000000000000000000000000000000000000000..904e71c3349ee1e097d8eff67f721c00f7092673 --- /dev/null +++ b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color/color.inc @@ -0,0 +1,20 @@ +<?php + +/** + * @file + * Lists available colors and color schemes for the Color test theme. + */ + +$info = array( + 'fields' => array( + 'bg' => t('Main background'), + ), + 'schemes' => array( + 'default' => array( + 'title' => t('Default'), + 'colors' => array( + 'bg' => '#ff0000', + ), + ), + ), +); diff --git a/core/modules/color/tests/modules/color_test/themes/color_test_theme/color_test_theme.info.yml b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color_test_theme.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ebd18ee611c0c6e7e5ea6ad34de1fb10deb6366 --- /dev/null +++ b/core/modules/color/tests/modules/color_test/themes/color_test_theme/color_test_theme.info.yml @@ -0,0 +1,6 @@ +name: 'Color test theme' +type: theme +description: 'Theme for testing the color module' +version: VERSION +core: 8.x +hidden: true diff --git a/core/themes/bartik/color/base.png b/core/themes/bartik/color/base.png deleted file mode 100644 index 58cc088a49e9259fefc2282f1795a5450f884065..0000000000000000000000000000000000000000 --- a/core/themes/bartik/color/base.png +++ /dev/null @@ -1,3 +0,0 @@ -�PNG - -��� IHDR����������Ո�����PLTE���������"IDATx^���������n��0������������1\�������IEND�B`� \ No newline at end of file diff --git a/core/themes/bartik/color/color.inc b/core/themes/bartik/color/color.inc index 0fe5ad5fc1b88dcfd8720a7bb67c4727c0c6b197..c741f9d08baec0669e9827fbe9d01a84708e6038 100644 --- a/core/themes/bartik/color/color.inc +++ b/core/themes/bartik/color/color.inc @@ -119,21 +119,8 @@ ), ), - // Color areas to fill (x, y, width, height). - 'fill' => array(), - - // Coordinates of all the theme slices (x, y, width, height) - // with their filename as used in the stylesheet. - 'slices' => array(), - - // Reference color used for blending. Matches the base.png's colors. - 'blend_target' => '#ffffff', - // Preview files. 'preview_css' => 'color/preview.css', 'preview_js' => 'color/preview.js', 'preview_html' => 'color/preview.html', - - // Base file for image generation. - 'base_image' => 'color/base.png', ); diff --git a/core/themes/bartik/color/preview.png b/core/themes/bartik/color/preview.png deleted file mode 100644 index 58cc088a49e9259fefc2282f1795a5450f884065..0000000000000000000000000000000000000000 --- a/core/themes/bartik/color/preview.png +++ /dev/null @@ -1,3 +0,0 @@ -�PNG - -��� IHDR����������Ո�����PLTE���������"IDATx^���������n��0������������1\�������IEND�B`� \ No newline at end of file