Commit e2e09698 authored by webchick's avatar webchick

#746500 by eojthebrave: Fixed Overriding default image styles does not work...

#746500 by eojthebrave: Fixed Overriding default image styles does not work with more than one effect and has potential to overwrite existing effects.
parent cca6d06c
......@@ -83,31 +83,36 @@ function image_style_form($form, &$form_state, $style) {
$form['effects'] = array(
'#theme' => 'image_style_effects',
);
foreach ($style['effects'] as $ieid => $effect) {
$form['effects'][$ieid]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$ieid]['weight'] : NULL;
$form['effects'][$ieid]['label'] = array(
foreach ($style['effects'] as $key => $effect) {
$form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
$form['effects'][$key]['label'] = array(
'#markup' => $effect['label'],
);
$form['effects'][$ieid]['summary'] = array(
$form['effects'][$key]['summary'] = array(
'#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array('data' => $effect['data'])) : '',
);
$form['effects'][$ieid]['weight'] = array(
$form['effects'][$key]['weight'] = array(
'#type' => 'weight',
'#default_value' => $effect['weight'],
'#access' => $editable,
);
$form['effects'][$ieid]['configure'] = array(
'#type' => 'link',
'#title' => t('edit'),
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'],
'#access' => $editable && isset($effect['form callback']),
);
$form['effects'][$ieid]['remove'] = array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'] . '/delete',
'#access' => $editable,
);
// Only attempt to display these fields for editable styles as the 'ieid'
// key is not set for styles defined in code.
if ($editable) {
$form['effects'][$key]['configure'] = array(
'#type' => 'link',
'#title' => t('edit'),
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'],
'#access' => $editable && isset($effect['form callback']),
);
$form['effects'][$key]['remove'] = array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'] . '/delete',
'#access' => $editable,
);
}
}
// Build the new image effect addition form and add it to the effect list.
......
......@@ -435,11 +435,10 @@ function image_styles() {
$style['name'] = $style_name;
$style['module'] = $module;
$style['storage'] = IMAGE_STORAGE_DEFAULT;
foreach ($style['effects'] as $ieid => $effect) {
foreach ($style['effects'] as $key => $effect) {
$definition = image_effect_definition_load($effect['name']);
$effect = array_merge($definition, $effect);
$effect['ieid'] = $ieid;
$style['effects'][$ieid] = $effect;
$style['effects'][$key] = $effect;
}
$styles[$style_name] = $style;
}
......@@ -834,7 +833,7 @@ function image_default_style_save($style) {
$effects = array();
foreach ($style['effects'] as $effect) {
$effect['isid'] = $style['isid'];
image_effect_save($effect);
$effect = image_effect_save($effect);
$effects[$effect['ieid']] = $effect;
}
$style['effects'] = $effects;
......
......@@ -536,6 +536,11 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
$image_path = $this->createSampleImage($style);
$this->assertEqual($this->getImageCount($style), 1, t('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
// Verify that effects attached to a default style do not have an ieid key.
foreach ($style['effects'] as $effect) {
$this->assertFalse(isset($effect['ieid']), t('The %effect effect does not have an ieid.', array('%effect' => $effect['name'])));
}
// Override the default.
$this->drupalPost($edit_path, array(), t('Override defaults'));
$this->assertRaw(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $style_name)), t('Default image style may be overridden.'));
......@@ -545,6 +550,11 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
drupal_static_reset('image_styles');
$style = image_style_load($style_name);
// Verify that effects attached to the style have an ieid now.
foreach ($style['effects'] as $effect) {
$this->assertTrue(isset($effect['ieid']), t('The %effect effect has an ieid.', array('%effect' => $effect['name'])));
}
// The style should now have 2 effect, the original scale provided by core
// and the desaturate effect we added in the override.
$effects = array_values($style['effects']);
......
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