diff -urp --strip-trailing-cr ../flatcomments/flatcomments_existing/flatcomments_existing.admin.inc ./flatcomments_existing/flatcomments_existing.admin.inc --- ../flatcomments/flatcomments_existing/flatcomments_existing.admin.inc 2009-05-17 20:37:55.000000000 +0200 +++ ./flatcomments_existing/flatcomments_existing.admin.inc 2009-05-17 22:05:08.000000000 +0200 @@ -9,24 +9,44 @@ /** * Form to select content types and confirm the operation. + * This is a multi-pass form, the confirmation being second pass. */ -function flatcomments_existing_form() { - $form['types'] = array( - '#type' => 'checkboxes', - '#title' => t('Flatten existing comments for content types'), - '#options' => node_get_types('names'), - '#description' => t('To remove all threading information from already existing comments, select content types you wish to process, and click "Execute". Warning: This operation breaks any previously existing threads into separate comments permanently, so there\'s no way to revert existing discussions back to threads afterwards.'), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Execute'), - ); - +function flatcomments_existing_form($form_state) { + if (empty($form_state['storage']['types'])) { + // First pass: Fresh form to select content types + $form['types'] = array( + '#type' => 'checkboxes', + '#title' => t('Flatten existing comments for content types'), + '#options' => node_get_types('names'), + '#description' => t('To remove all threading information from already existing comments, select content types you wish to process, and click "Execute". Warning: This operation breaks any previously existing threads into separate comments permanently, so there\'s no way to revert existing discussions back to threads afterwards.'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Execute'), + ); + $form['#submit'] = array('flatcomments_existing_form_submit_1'); + } + else { + // Second pass: Confirmation screen + $form['types'] = array( + '#type' => 'value', + '#value' => $form_state['storage']['types'], // Keep the selection from first pass + ); + $form['#submit'] = array('flatcomments_existing_form_submit_2'); + $form = confirm_form($form, + t('Are you sure you want to remove threading information?'), + 'admin/content/comment/flatten', + t('This operation breaks any previously existing threads into separate comments permanently. It cannot be undone.'), + t('Continue'), + t('Cancel') + ); + } return $form; } /** - * Form validation; checks that node type(s) are selected, and all valid + * Form validation; checks that node type(s) are selected, and all valid. + * (Note: The checks are executed on both passes of the form.) */ function flatcomments_existing_form_validate($form, &$form_state) { $content_types = node_get_types('names'); @@ -48,9 +68,22 @@ function flatcomments_existing_form_vali } /** - * Form submit handler; starts a batch of required operations. + * Form submit handler - first pass. Triggers second pass for confirmation. + */ +function flatcomments_existing_form_submit_1($form, &$form_state) { + // Pass the submitted selection of content types to the second pass. + // The existence of $form_state['storage'] triggers the second pass + // of the form being rendered in our code, as well as in the FAPI. + $form_state['storage']['types'] = $form_state['values']['types']; +} + +/** + * Form submit handler - second pass. Starts a batch of required operations. */ -function flatcomments_existing_form_submit($form, &$form_state) { +function flatcomments_existing_form_submit_2($form, &$form_state) { + // Reset the form to show first pass when finished. + $form_state['storage'] = NULL; + $content_types = node_get_types('names'); $processed_types = array(); $batch = array('file' => __FILE__); diff -urp --strip-trailing-cr ../flatcomments/flatcomments_existing/flatcomments_existing.install ./flatcomments_existing/flatcomments_existing.install --- ../flatcomments/flatcomments_existing/flatcomments_existing.install 2009-05-17 20:38:13.000000000 +0200 +++ ./flatcomments_existing/flatcomments_existing.install 2009-05-17 20:41:47.000000000 +0200 @@ -10,5 +10,5 @@ * Implementation of hook_enable(). */ function flatcomments_existing_enable() { - drupal_set_message(t('Flatcomments Exising successfully installed. Go to admin/content/comment/flatten to flatten comments.', array('!url' => url('admin/content/comment/flatten')))); + drupal_set_message(t('Flatcomments Existing successfully installed. Go to admin/content/comment/flatten to flatten existing comments.', array('!url' => url('admin/content/comment/flatten')))); } diff -urp --strip-trailing-cr ../flatcomments/flatcomments_existing/flatcomments_existing.module ./flatcomments_existing/flatcomments_existing.module --- ../flatcomments/flatcomments_existing/flatcomments_existing.module 2009-05-17 20:38:23.000000000 +0200 +++ ./flatcomments_existing/flatcomments_existing.module 2009-05-17 20:46:30.000000000 +0200 @@ -28,7 +28,6 @@ function flatcomments_existing_menu() { 'page callback' => 'drupal_get_form', 'page arguments' => array('flatcomments_existing_form'), 'access callback' => 'flatcomments_existing_flatten_access', - //'access arguments' => array('administer comments', 'administer nodes', 'administer content types'), 'file' => 'flatcomments_existing.admin.inc', 'type' => MENU_LOCAL_TASK, ); @@ -37,8 +36,5 @@ function flatcomments_existing_menu() { } function flatcomments_existing_flatten_access() { - if (user_access('administer comments') && user_access('administer nodes') && user_access('administer content types')) { - return TRUE; - } - return FALSE; + return (user_access('administer comments') && user_access('administer nodes') && user_access('administer content types')); }