Index: imagecache_image.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/Attic/imagecache_image.module,v retrieving revision 1.1.2.1 diff -u -p -r1.1.2.1 imagecache_image.module --- imagecache_image.module 7 Jul 2008 02:56:49 -0000 1.1.2.1 +++ imagecache_image.module 6 Oct 2008 10:28:12 -0000 @@ -1,8 +1,7 @@ "(no imagecache process)"); + $imagecache_options = array(); foreach($presets as $preset) { $imagecache_options[$preset['presetid']] = $preset['presetname']; } - foreach(element_children($form['image_sizes']) as $key){ + // Add our imagecache presest as extended 'operations' + $form['image_sizes'][$key]['operation']['#options'] = $form['image_sizes'][$key]['operation']['#options'] + $imagecache_options; + if($sizes[$key]['imagecache']) { + $form['image_sizes'][$key]['operation']['#default_value'] = $sizes[$key]['imagecache']; + } ; + // This is the real value that the selector should influence. $form['image_sizes'][$key]['imagecache'] = array( - '#type' => 'select', + '#type' => 'hidden', '#default_value' => $sizes[$key]['imagecache'], - '#options' => $imagecache_options, ); - $form['image_sizes'][$key]['operation']['#type'] = 'hidden'; - $form['image_sizes'][$key]['width']['#type'] = 'hidden'; - $form['image_sizes'][$key]['height']['#type'] = 'hidden'; + // Hide unused elements + $operation = $form['image_sizes'][$key]['operation']['#default_value']; + if( ($operation != 'scale') && ($operation != 'scale_crop') ) { + $form['image_sizes'][$key]['width']['#value'] = 1; + $form['image_sizes'][$key]['width']['#type'] = 'hidden'; + $form['image_sizes'][$key]['height']['#value'] = 1; + $form['image_sizes'][$key]['height']['#type'] = 'hidden'; + } } - $form['image_sizes']['#description'] .= t('

Note: \'Original\' dimensions - will only be used to resize images when they are first uploaded. Existing - originals will not be modified. Choose an imagecache preset - to use to generate this derivative image.

', + $form['image_sizes']['#description'] .= t('

+ Choose an imagecache preset + to use to generate this derivative image. If using imagecache, the operation and sizes shown here will be ignored

', array('!imagecache_settings' => url('admin/build/imagecache')) ); - $form['image_sizes']['#theme'] = 'imagecache_image_settings_sizes_form'; - - // Capture the form submission so we can save this setting - $form['#submit']['imagecache_save_image_size_settings'] = array(); + // We switch values behind the scenes, and incidentally bypass the normal image.module validation. + $form['image_sizes']['#validate'] = array('imagecache_change_image_size_settings' => array() ); } } -function theme_imagecache_image_settings_sizes_form(&$form) { - $header = array(t('Label'), t('Imagecache Preset'), t('Link')); - foreach (element_children($form) as $key) { - $row = array(); - $row[] = drupal_render($form[$key]['label']); - $row[] = drupal_render($form[$key]['imagecache']); - $row[] = drupal_render($form[$key]['link']); - $rows[] = $row; +/** + * Manipulate the settings being saved ... to fool image.module + * + * Reads the operation, saves it in our own imagecache setting, then resets the + * operation to something image.module will recognise. + * It's pulling a bait and switch with the form - all just to clean up the UI. + * + * TODO Image.module could co-operate a bit more by extending the 'operations' + * for us to add to directly. So call this a proof-of concept until a better + * way. + */ +function imagecache_change_image_size_settings(&$form) { + foreach (element_children($form) as $preset_id) { + $operation = $form[$preset_id]['operation']['#value']; + if (($operation != 'scale') && ($operation != 'scale_crop')) { + form_set_value($form[$preset_id]['imagecache'], $operation); + form_set_value($form[$preset_id]['operation'], 'scale'); + if(!($form[$preset_id]['width'] || $form[$preset_id]['height'])) { + // Dummy values to fudge it even more for image.module + form_set_value($form[$preset_id]['width'], 100, $form_state); + form_set_value($form[$preset_id]['height'], 100, $form_state); + } + } + else { + form_set_value($form[$preset_id]['imagecache'], ''); + } } - $output .= theme('table', $header, $rows); - $output .= drupal_render($form); - - return $output; } - - /** * Implementation of hook_image_alter() * @@ -86,4 +101,3 @@ function imagecache_image_alter($node, $ $result = imagecache_build_derivative($preset['actions'], $original, $destination ); } } -