Commit a9be94a5 authored by webchick's avatar webchick

Issue #924322 by tim.plunkett, Devin Carlson, dicix, mike stewart | Jeff...

Issue #924322 by tim.plunkett, Devin Carlson, dicix, mike stewart | Jeff Burnz: Color_scheme_form_submit() assumes color.inc provides keys that should be optional.
parent c24feeee
......@@ -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);
}
......
......@@ -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');
......
name: 'Color test'
type: module
description: 'Provides test helpers for color module.'
package: Testing
version: VERSION
core: 8.x
hidden: true
<?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;
}
<?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',
),
),
),
);
name: 'Color test theme'
type: theme
description: 'Theme for testing the color module'
version: VERSION
core: 8.x
hidden: true
......@@ -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',
);
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