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])) {
$effect = $style['effects'][$ieid];
$effect['weight'] = $effect_data['weight'];
$effect['style_name'] = $style['name'];
image_effect_save($effect);
}
}
@ -358,9 +359,12 @@ function image_effect_form($form, &$form_state, $style, $effect) {
* Submit handler for updating an image effect.
*/
function image_effect_form_submit($form, &$form_state) {
$style = $form_state['image_style'];
$effect = array_merge($form_state['image_effect'], $form_state['values']);
$effect['style_name'] = $style['name'];
$effect = array(
'name' => $form_state['image_effect']['name'],
'data' => $form_state['values']['data'],
'weight' => $form_state['values']['weight'],
'style_name' => $form_state['image_style']['name'],
);
image_effect_save($effect);
drupal_set_message(t('The image effect was successfully applied.'));
$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) {
$config = config('image.styles.' . $style['name']);
$config->set('name', $style['name']);
$config->set('effects', array());
if ($style['effects']) {
$config->set('effects', $style['effects']);
}
else {
$config->set('effects', array());
}
$config->save();
$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.
*/
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'])) {
$old_effect = $config->get('effects.' . $effect['ieid']);
foreach ($old_effect as $key => $value) {
@ -1013,16 +1021,17 @@ function image_effect_save($effect) {
else {
// We need to generate the ieid and save the new effect.
// The machine name is all the elements of the data array concatenated
// together, delimited by underscores.
$machine_name = $data['name'];
// together, delimited by underscores.
$machine_name = $effect['name'];
foreach ($effect['data'] as $key => $value) {
$machine_name .= '_' . $value;
}
$effect['ieid'] = $machine_name;
$config->set('effects.' . $effect[$machine_name], $effect);
$config->set('effects.' . $machine_name, $effect);
}
$config->save();
$style = image_style_load(NULL, $effect['style_name']);
$style = image_style_load(NULL, $style_name);
image_style_flush($style);
return $effect;
}