? .cvsignore
? .str_vs_preg.php.swp
? str_vs_preg.php.txt
? working.patch
Index: imagecache_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_ui.module,v
retrieving revision 1.31
diff -u -p -r1.31 imagecache_ui.module
--- imagecache_ui.module	3 May 2009 16:14:24 -0000	1.31
+++ imagecache_ui.module	3 May 2009 16:57:58 -0000
@@ -95,8 +95,8 @@ function imagecache_ui_menu() {
     'title callback' => 'imagecache_preset_title_callback',
     'title arguments' => array('Add !actionname to !presetname', 3, 5),
     'file' => 'imagecache_ui.pages.inc',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('imagecache_ui_action_add_form', 3, 5),
+    'page callback' => 'imagecache_ui_action_add_page',
+    'page arguments' => array(3, 5),
     'access arguments' => array('administer imagecache'),
     'type' => MENU_CALLBACK,
   );
Index: imagecache_ui.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_ui.pages.inc,v
retrieving revision 1.4
diff -u -p -r1.4 imagecache_ui.pages.inc
--- imagecache_ui.pages.inc	3 May 2009 16:14:24 -0000	1.4
+++ imagecache_ui.pages.inc	3 May 2009 16:57:58 -0000
@@ -351,33 +351,50 @@ function theme_imagecache_ui_preset_acti
 }
 
 
-function imagecache_ui_action_form($form_state, $preset, $action) {
-  $definitions = imagecache_action_definitions();
-
-  if (empty($action)) {
-    drupal_set_message(t('Unknown Action.'), 'error');
-    drupal_goto('admin/build/imagecache');
+/**
+ * Page with form for adding a new action to add to a preset.
+ */
+function imagecache_ui_action_add_page($preset, $actionname) {
+  // Make sure the name is valid.
+  if (!imagecache_action_definition($actionname)) {
+    drupal_set_message(t('Unknown action.'), 'error');
+    drupal_goto('admin/build/imagecache/'. $preset['presetid']);
   }
 
-  if (empty($preset)) {
-    drupal_set_message(t('Unknown Preset.'), 'error');
+  $action = array(
+    'presetid' => $preset['presetid'],
+    'action' => $actionname,
+  );
+  return drupal_get_form('imagecache_ui_action_form', $preset, $action);
+}
+
+
+function imagecache_ui_action_form($form_state, $preset, $action) {
+  // Do some error checking.
+  if (empty($preset['presetid'])) {
+    drupal_set_message(t('Unknown preset.'), 'error');
     drupal_goto('admin/build/imagecache');
   }
+  if (empty($action['action']) || !$definition = imagecache_action_definition($action['action'])) {
+    drupal_set_message(t('Unknown action.'), 'error');
+    drupal_goto('admin/build/imagecache/'. $preset['presetid']);
+  }
+  if ($action['presetid'] != $preset['presetid']) {
+    drupal_set_message(t('This %action action is not associated %preset preset.', array('%action' => $action['action'], '%preset' => $preset['presetname'])), 'error');
+    drupal_goto('admin/build/imagecache/'. $preset['presetid']);
+  }
 
-  $form = array(
-    '#tree' => TRUE,
-  );
-
+  $form['#tree'] = TRUE;
   $form['actionid'] = array(
     '#type' => 'value',
     '#value' => $action['actionid'],
   );
-
-
-  if (!empty($definitions[$action['action']]['file'])) {
-    require_once($definitions[$action['action']]['file']);
+  if (!empty($definition['file'])) {
+    require_once($definition['file']);
+  }
+  if (function_exists($action['action'] .'_form')) {
+    $form['data'] = call_user_func($action['action'] .'_form', $action['data']);
   }
-  $form['data'] = call_user_func($action['action'] .'_form', $action['data']);
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Update Action'),
@@ -390,12 +407,12 @@ function imagecache_ui_action_form_submi
     $action = array_merge($action, $form_state['values']);
     imagecache_action_save($action);
     drupal_set_message(t('The action was succesfully updated.'));
-    $form_state['redirect'] = 'admin/build/imagecache/'. $action['presetid'];
   }
   else {
-    drupal_set_message(t('Unknown Action: @action_id', array('@action_id' => $form_state['values']['actionid'])));
-    $form_state['redirect'] = 'admin/build/imagecache';
+    imagecache_action_save($form_state['values']);
+    drupal_set_message(t('The action was succesfully created.'));
   }
+  $form_state['redirect'] = 'admin/build/imagecache/'. $action['presetid'];
 }
 
 
@@ -428,36 +445,3 @@ function imagecache_ui_action_delete_for
   drupal_set_message(t('The action has been deleted.'));
   $form_state['redirect'] = 'admin/build/imagecache/'. $action['presetid'];
 }
-
-
-function imagecache_ui_action_add_form($form_state, $preset, $actionname) {
-  $definition = imagecache_action_definition($actionname);
-
-  $form = array(
-    '#tree' => TRUE,
-  );
-  $form['action'] = array(
-    '#type' => 'value',
-    '#value' => $actionname,
-  );
-  $form['presetid'] = array(
-    '#type' => 'value',
-    '#value' => $preset['presetid'],
-  );
-  $form['weight'] = array(
-    '#type' => 'weight',
-    '#title' => t('Weight'),
-  );
-
-  $form['data'] = call_user_func($actionname .'_form', array());
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Add Action'),
-  );
-  return $form;
-}
-
-function imagecache_ui_action_add_form_submit($form, &$form_state) {
-  imagecache_action_save($form_state['values']);
-  $form_state['redirect'] = 'admin/build/imagecache/'. $form_state['values']['presetid'];
-}
