Index: customdestination.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/customdestination/customdestination.install,v
retrieving revision 1.2
diff -u -r1.2 customdestination.install
--- customdestination.install	4 Jul 2009 21:21:53 -0000	1.2
+++ customdestination.install	19 Feb 2010 07:07:45 -0000
@@ -1,32 +1,69 @@
 <?php
+// $Id$
+
+/**
+ * @file
+ * Installation of Custom Destination.
+ */
+
+/**
+ * Implementation of hook_schema().
+ */
 function customdestination_schema() {
   $schema['customdestination'] = array(
-    'description' => 'The base table for customdestinations.',
+    'description' => t('The base table for customdestinations.'),
     'fields' => array(
       'fid' => array(
-        'description' => 'The form ID of this customdestination.',
+        'description' => t('The form ID of this customdestination.'),
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
         'default' => ''),
       'dst' => array(
-        'description' => 'The custom destination for this form ID.',
+        'description' => t('The custom destination for this form ID.'),
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
         'default' => ''),
-      ),
+      'clear_dsm' => array(
+        'description' => t('Status on whether or not to clear messages when redirecting.'),
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 0),
+    ),
     'primary key' => array('fid'),
   );
   return $schema;
 }
 
+/**
+ * Implementation of hook_install().
+ */
 function customdestination_install() {
   // Create my tables.
   drupal_install_schema('customdestination');
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
 function customdestination_uninstall() {
   // Drop my tables.
   drupal_uninstall_schema('customdestination');
 }
+
+/**
+ * Add the clear_dsm field.
+ */
+function customdestination_update_6000() {
+  $ret = array();
+  db_add_field($ret, 'customdestination', 'clear_dsm', array(
+    'description' => t('Status on whether or not to clear messages when redirecting.'),
+    'type' => 'int',
+    'size' => 'tiny',
+    'not null' => TRUE,
+    'default' => 0)
+  );
+  return $ret;
+}
Index: customdestination.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/customdestination/customdestination.module,v
retrieving revision 1.8
diff -u -r1.8 customdestination.module
--- customdestination.module	6 Nov 2009 11:38:33 -0000	1.8
+++ customdestination.module	19 Feb 2010 07:07:46 -0000
@@ -2,6 +2,11 @@
 // $Id: customdestination.module,v 1.8 2009/11/06 11:38:33 flevour Exp $
 
 /**
+ * @file
+ * Redirects specific forms to an alternate location.
+ */
+
+/**
  * Implementation of hook_help().
  */
 function customdestination_help($path, $arg) {
@@ -15,14 +20,14 @@
 }
 
 /**
-* Implementation of hook_perm().
-*/
+ * Implementation of hook_perm().
+ */
 function customdestination_perm() {
   return array('administer custom destination');
 }
 
 /**
- * Implementation of hook_menu
+ * Implementation of hook_menu().
  */
 function customdestination_menu() {
   $items['admin/settings/customdestination'] = array(
@@ -40,20 +45,20 @@
     'title' => 'Add custom destination',
     'description' => 'Add a new custom destination',
     'page callback' => 'customdestination_edit',
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('administer custom destination'),
     'type' => MENU_LOCAL_TASK,
   );
   $items['admin/settings/customdestination/edit'] = array(
     'title' => 'Edit',
     'page callback' => 'customdestination_edit',
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('administer custom destination'),
     'type' => MENU_CALLBACK,
   );
   $items['admin/settings/customdestination/delete'] = array(
     'title' => 'Delete custom destination',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('customdestination_delete_confirm'),
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('administer custom destination'),
     'type' => MENU_CALLBACK,
   );
 
@@ -83,7 +88,7 @@
  * @see customdestination_form_validate()
  * @see customdestination_form_submit()
  */
-function customdestination_form(&$form_state, $edit = array('fid' => '', 'dst' => '')) {
+function customdestination_form(&$form_state, $edit = array('fid' => '', 'dst' => '', 'clear_dsm' => 0)) {
   $form['fid'] = array(
     '#type' => 'textfield',
     '#title' => t('Form ID'),
@@ -100,6 +105,13 @@
     '#description' => t("The destination to redirect to upon form submission. No leading and trailing slash."),
     '#required' => TRUE,
   );
+  $form['clear_dsm'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Wipe messages on destination'),
+    '#default_value' => $edit['clear_dsm'],
+    '#required' => FALSE,
+    '#description' => t('Suppress any status, warning, or error messages that would otherwise display on the destination page.')
+  );
   if ($edit['fid']) {
     // use hidden value here if can't usere INSERT OR UPDATE
     $form['submit'] = array('#type' => 'submit', '#value' => t('Update custom destination'));
@@ -115,7 +127,7 @@
  * Save a new custom destination to the database.
  */
 function customdestination_form_submit($form, &$form_state) {
-  customdestination_save($form_state['values']['fid'], $form_state['values']['dst']);
+  customdestination_save($form_state['values']['fid'], $form_state['values']['dst'], $form_state['values']['clear_dsm']);
 
   drupal_set_message(t('The custom destination has been saved.'));
   $form_state['redirect'] = 'admin/settings/customdestination';
@@ -133,14 +145,14 @@
   /* if (!_customdestination_form_exists($fid)) {
     form_set_error('fid', t("The form id '@form_id' doesn't exist in the system.", array('@form_id' => $fid)));
   } */
-  
+
   // check if form id is valid
   if (!preg_match("/[a-z_0-9]+/", $fid)) {
     form_set_error('fid', t("The form '@form_id' is invalid. A valid form ID contains only alphanumeric characters and underscores.", array('@form_id' => $fid)));
   }
-  
+
   // check if destination exists and is accessible by the current user
-  if (!menu_valid_path(array('link_item' => $dst))) {
+  if (!menu_valid_path(array('link_path' => $dst))) {
     form_set_error('dst', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $dst)));
   }
 }
@@ -160,7 +172,7 @@
 }
 
 /**
- * Execute URL alias deletion
+ * Execute URL alias deletion.
  */
 function customdestination_delete_confirm_submit($form, &$form_state) {
   if ($form_state['values']['confirm']) {
@@ -174,7 +186,7 @@
  * Fetch a specific custom destination from the database.
  */
 function customdestination_load($fid) {
-  return db_fetch_array(db_query("SELECT * FROM {customdestination} WHERE fid = '%s'", $fid));
+  return db_fetch_array(db_query_range("SELECT * FROM {customdestination} WHERE fid = '%s'", $fid, 0, 1));
 }
 
 /**
@@ -187,21 +199,22 @@
 /**
  * Save a custom destination to the database.
  */
-function customdestination_save($fid, $dst) {
+function customdestination_save($fid, $dst, $clear_dsm) {
   $customdestination = customdestination_load($fid);
   if (!empty($customdestination)) {
     // There is already a custom destination defined for this fid
     // Update the entry with new dst
-    db_query("UPDATE {customdestination} SET dst = '%s' WHERE fid = '%s'", $dst, $fid);
+    db_query("UPDATE {customdestination} SET dst = '%s', clear_dsm = %d WHERE fid = '%s'", $dst, $clear_dsm, $fid);
   }
   else {
     // A new custom destination. Add it to the database.
-    db_query("INSERT INTO {customdestination} (fid, dst) VALUES ('%s', '%s')", $fid, $dst);
+    db_query("INSERT INTO {customdestination} (fid, dst, clear_dsm) VALUES ('%s', '%s', %d)", $fid, $dst, $clear_dsm);
   }
 }
 
 /**
  * Return a listing of all defined URL aliases.
+ *
  * When filter key passed, perform a standard search on the given key,
  * and return the list of matching URL aliases.
  */
@@ -211,6 +224,7 @@
   $header = array(
     array('data' => t('Form ID'), 'field' => 'fid', 'sort' => 'asc'),
     array('data' => t('Destination'), 'field' => 'dst'),
+    array('data' => t('Clear messages'), 'field' => 'clear_dsm'),
     array('data' => t('Operations'), 'colspan' => '2')
   );
 
@@ -220,12 +234,12 @@
   $rows = array();
   $destination = drupal_get_destination();
   while ($data = db_fetch_object($result)) {
-    $row = array(check_plain($data->fid), check_plain($data->dst), l(t('edit'), "admin/settings/customdestination/edit/$data->fid", array('query' => $destination)), l(t('delete'), "admin/settings/customdestination/delete/$data->fid", array('query' => $destination)));
+    $row = array(check_plain($data->fid), check_plain($data->dst), $data->clear_dsm ? t('On') : t('Off'), l(t('edit'), "admin/settings/customdestination/edit/$data->fid", array('query' => $destination)), l(t('delete'), "admin/settings/customdestination/delete/$data->fid", array('query' => $destination)));
     $rows[] = $row;
   }
 
   if (empty($rows)) {
-    $rows[] = array(array('data' => t('No custom destinations found.'), 'colspan' => 4));
+    $rows[] = array(array('data' => t('No custom destinations found.'), 'colspan' => 5));
   }
 
   $output .= theme('table', $header, $rows);
@@ -235,12 +249,26 @@
 }
 
 /**
- * The core of the module, form_alter #redirect value with custom destination
+ * The core of the module, form_alter #redirect value with custom destination.
  */
 function customdestination_form_alter(&$form, $form_state, $form_id) {
   $customdestination = customdestination_load($form_id);
   if (!empty($customdestination)) {
     $form['#redirect'] = $customdestination['dst'];
+    if ($customdestination['clear_dsm'] > 0) {
+      $form['#submit'][] = 'customdestination_clear_dsm';
+    }
   }
 }
 
+function customdestination_clear_dsm($form = array(), &$form_state = array()) {
+  static $form_set;
+  if (!empty($form) || !empty($form_set)) {
+    $form_set = TRUE;
+    $_SESSION['messages'] = array();
+  }
+}
+
+function customdestination_exit() {
+  customdestination_clear_dsm();
+}
Index: customdestination.test
===================================================================
RCS file: customdestination.test
diff -N customdestination.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ customdestination.test	19 Feb 2010 07:07:46 -0000
@@ -0,0 +1,84 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Tests the settings form of Custom (Form) Destination.
+ */
+
+class CustomDestinationTestCase extends DrupalWebTestCase {
+  protected $privileged_user;
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => t('Redirect and message checks'),
+      'description' => t('Ensure that the custom destionation paths and message removal functions properly.'),
+      'group' => t('Custom (Form) Destination'),
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  public function setUp() {
+    parent::setUp('customdestination');  // Enable any modules required for the test
+    // Create and log in our privileged user.
+    $this->privileged_user = $this->drupalCreateUser(array('administer permissions', 'access administration pages', 'administer custom destination'));
+    $this->drupalLogin($this->privileged_user);
+  }
+
+  public function testSettings() {
+    $this->drupalGet('admin/settings/customdestination');
+    $this->clickLink('Add custom destination');
+    $this->assertFieldByID('edit-fid', '', 'Found edit-fid as indication that we got to the settings page.');
+    $this->assertFieldByID('edit-dst', '', 'Found edit-dst as indication that we got to the settings page.');
+    $this->assertField('edit-clear-dsm', 'Found edit-clear-dsm as indication that we got to the settings page.');
+    $edit = array(
+      'fid' => 'customdestination_form',
+      'dst' => 'admin/settings',
+      'clear_dsm' => FALSE
+    );
+    $this->drupalPost(NULL, $edit, t('Create new custom destination'));
+    $this->verbose('First new destination set: '. var_export($edit, TRUE));
+
+    $this->assertText(t('The custom destination has been saved.'));
+
+    $this->clickLink('edit');
+
+    $this->assertFieldByID('edit-fid', 'customdestination_form', 'Found edit-fid as indication that we got to the settings page.');
+    $this->assertFieldByID('edit-dst', 'admin/settings', 'Found edit-dst as indication that we got to the settings page.');
+    $this->assertField('edit-clear-dsm', 'Found edit-clear-dsm as indication that we got to the settings page.');
+    $edit = array(
+      'fid' => 'user_admin_new_role',
+      'dst' => 'admin/settings',
+      'clear_dsm' => TRUE
+    );
+    $this->drupalPost(NULL, $edit, t('Update custom destination'));
+    $this->verbose('Destination updated: '. var_export($edit, TRUE));
+
+    $this->assertText('user_admin_new_role');
+    $this->assertText('customdestination_form');
+    $this->assertText('admin/settings');
+
+    // Though we just turned on suppression, it shouldn't have kicked in yet.
+    $this->assertText(t('The custom destination has been saved.'));
+
+    $this->drupalGet('admin/user/roles');
+
+    $this->assertFieldByID('edit-name', '', 'Found edit-name as indication that we got to the user roles page.');
+    $edit = array(
+      'name' => 'test role'
+    );
+    $this->drupalPost(NULL, $edit, t('Add role'));
+    $this->verbose('test role added: '. var_export($edit, TRUE));
+
+    $this->assertEqual(url('admin/settings', array('absolute' => TRUE)), $this->getURL(), 'New destination was successful.');
+    $this->assertNoText(t('The role has been added.'));
+
+    $this->drupalGet('admin/user/roles');
+    $this->assertText('test role', 'Test role found in role list.');
+  }
+}
