Work in progress

8.0.x
Greg Dunlap 2012-01-07 10:43:37 +01:00
parent 5ed90e0fcd
commit cc50837569
2 changed files with 22 additions and 9 deletions

View File

@ -184,6 +184,7 @@ function image_style_form_submit($form, &$form_state) {
if (isset($style['effects'][$ieid])) { if (isset($style['effects'][$ieid])) {
$effect = $style['effects'][$ieid]; $effect = $style['effects'][$ieid];
$effect['weight'] = $effect_data['weight']; $effect['weight'] = $effect_data['weight'];
$effect['style_name'] = $style['name'];
image_effect_save($effect); image_effect_save($effect);
} }
} }
@ -358,9 +359,12 @@ function image_effect_form($form, &$form_state, $style, $effect) {
* Submit handler for updating an image effect. * Submit handler for updating an image effect.
*/ */
function image_effect_form_submit($form, &$form_state) { function image_effect_form_submit($form, &$form_state) {
$style = $form_state['image_style']; $effect = array(
$effect = array_merge($form_state['image_effect'], $form_state['values']); 'name' => $form_state['image_effect']['name'],
$effect['style_name'] = $style['name']; 'data' => $form_state['values']['data'],
'weight' => $form_state['values']['weight'],
'style_name' => $form_state['image_style']['name'],
);
image_effect_save($effect); image_effect_save($effect);
drupal_set_message(t('The image effect was successfully applied.')); drupal_set_message(t('The image effect was successfully applied.'));
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name']; $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];

View File

@ -501,7 +501,12 @@ function image_style_load($name = NULL) {
function image_style_save($style) { function image_style_save($style) {
$config = config('image.styles.' . $style['name']); $config = config('image.styles.' . $style['name']);
$config->set('name', $style['name']); $config->set('name', $style['name']);
if ($style['effects']) {
$config->set('effects', $style['effects']);
}
else {
$config->set('effects', array()); $config->set('effects', array());
}
$config->save(); $config->save();
$style['is_new'] = TRUE; $style['is_new'] = TRUE;
@ -1002,7 +1007,10 @@ function image_effect_load($name, $style_name) {
* An image effect array. In the case of a new effect, 'ieid' will be set. * An image effect array. In the case of a new effect, 'ieid' will be set.
*/ */
function image_effect_save($effect) { function image_effect_save($effect) {
$config = config('image.styles.' . $effect['name']); $style_name = $effect['style_name'];
unset($effect['style_name']);
$config = config('image.styles.' . $style_name);
if (!empty($effect['ieid'])) { if (!empty($effect['ieid'])) {
$old_effect = $config->get('effects.' . $effect['ieid']); $old_effect = $config->get('effects.' . $effect['ieid']);
foreach ($old_effect as $key => $value) { foreach ($old_effect as $key => $value) {
@ -1014,15 +1022,16 @@ function image_effect_save($effect) {
// We need to generate the ieid and save the new effect. // We need to generate the ieid and save the new effect.
// The machine name is all the elements of the data array concatenated // The machine name is all the elements of the data array concatenated
// together, delimited by underscores. // together, delimited by underscores.
$machine_name = $data['name']; $machine_name = $effect['name'];
foreach ($effect['data'] as $key => $value) { foreach ($effect['data'] as $key => $value) {
$machine_name .= '_' . $value; $machine_name .= '_' . $value;
} }
$effect['ieid'] = $machine_name; $effect['ieid'] = $machine_name;
$config->set('effects.' . $effect[$machine_name], $effect); $config->set('effects.' . $machine_name, $effect);
} }
$config->save(); $config->save();
$style = image_style_load(NULL, $effect['style_name']); $style = image_style_load(NULL, $style_name);
image_style_flush($style); image_style_flush($style);
return $effect; return $effect;
} }