Moderation reasons state is not saved when going from node edit to node delete confirmation page.

Comments

mikhailian’s picture

I was naive and tried this:

diff --git a/moderation_log.module b/moderation_log.module
index 98c3adb..5eb4e70 100644
--- a/moderation_log.module
+++ b/moderation_log.module
@@ -372,10 +372,21 @@ function moderation_log_form_alter(&$form, &$form_state, $form_id) {
       $form['moderation_log']['moderation_reason'] = array(
         '#type' => 'checkboxes',
         '#parents' => array('moderation_log'),
-        '#options' => $_moderation_reason
+        '#options' => $_moderation_reason,
+        '#default_value' => $form_state['storage']['moderation_log']
       );
+      if ($form_id == "forum_node_form" || $form_id == "comment_form") {
+        $form['buttons']['submit']['#submit'][] = 'moderation_log_moderationreason_submit';
+        $form['buttons']['preview']['#submit'][] = 'moderation_log_moderationreason_submit';
+        $form['buttons']['delete']['#submit'][] = 'moderation_log_moderationreason_submit';
+      }
     }
   }
   return $form;
 }
 
+/** manual here http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_form_alter/6#comment-2118 */
+function moderation_log_moderationreason_submit($form, &$form_state) {
+  $form_state['storage']['moderation_log'] = array_filter(array_values($form_state['values']['moderation_log']));
+}
+

Unfortunately, the code above will not work, because there is a redirect after the user hits the Delete button on node edit page, which effectively erases all form_state['storage'] contents. Moreover, there will be no redirect, either, because

      // snippet from includes/form.inc:449..457.
      // If no submit handlers have populated the $form_state['storage']
      // bundle, and the $form_state['rebuild'] flag has not been set,
      // we're finished and should redirect to a new destination page
      // if one has been set (and a fresh, unpopulated copy of the form
      // if one hasn't). If the form was called by drupal_execute(),
      // however, we'll skip this and let the calling function examine
      // the resulting $form_state bundle itself.
      if (!$form['#programmed'] && empty($form_state['rebuild']) && empty($form_state['storage'])) {
        drupal_redirect_form($form, $form_state['redirect']);