diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-02-01 06:48:15 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-02-01 06:48:15 +0000 |
commit | 5e2ad8e43cc6e5aad12a5b4be3d310477498d3b4 (patch) | |
tree | e56890eb11e3920e05d0cd97348e462b8ab499b9 /modules | |
parent | f12b1b637f748051c1fd9e260881208092bf913b (diff) | |
download | brdo-5e2ad8e43cc6e5aad12a5b4be3d310477498d3b4.tar.gz brdo-5e2ad8e43cc6e5aad12a5b4be3d310477498d3b4.tar.bz2 |
#360128 by quicksketch: Create centralized ahah callback to reduce duplicate code.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/poll/poll.module | 44 | ||||
-rw-r--r-- | modules/poll/poll.test | 2 | ||||
-rw-r--r-- | modules/system/system.module | 6 |
3 files changed, 14 insertions, 38 deletions
diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 86ceee59d..45de98605 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -118,13 +118,6 @@ function poll_menu() { 'type' => MENU_LOCAL_TASK, ); - $items['poll/js'] = array( - 'title' => 'Javascript Choice Form', - 'page callback' => 'poll_choice_js', - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - return $items; } @@ -266,7 +259,7 @@ function poll_form(&$node, $form_state) { '#weight' => 1, '#submit' => array('poll_more_choices_submit'), // If no javascript action. '#ahah' => array( - 'path' => 'poll/js', + 'callback' => 'poll_choice_js', 'wrapper' => 'poll-choices', 'method' => 'replace', 'effect' => 'fade', @@ -315,7 +308,7 @@ function poll_more_choices_submit($form, &$form_state) { // Make the changes we want to the form state. if ($form_state['values']['poll_more']) { - $n = $_GET['q'] == 'poll/js' ? 1 : 5; + $n = $_GET['q'] == 'system/ahah' ? 1 : 5; $form_state['choice_count'] = count($form_state['values']['choice']) + $n; } } @@ -361,36 +354,13 @@ function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight } /** - * Menu callback for AHAH additions. + * Menu callback for AHAH additions. Render the new poll choices. */ -function poll_choice_js() { - $form_state = array('storage' => NULL, 'submitted' => FALSE); - $form_build_id = $_POST['form_build_id']; - - // Get the form from the cache. - $form = form_get_cache($form_build_id, $form_state); - $args = $form['#parameters']; - $form_id = array_shift($args); - - // We will run some of the submit handlers so we need to disable redirecting. - $form['#redirect'] = FALSE; - - // We need to process the form, prepare for that by setting a few internals - // variables. - $form['#post'] = $_POST; - $form['#programmed'] = FALSE; - $form_state['post'] = $_POST; - - // Build, validate and if possible, submit the form. - drupal_process_form($form_id, $form, $form_state); - - // This call recreates the form relying solely on the form_state that the - // drupal_process_form set up. - $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); - - // Render the new output. +function poll_choice_js($form, $form_state) { $choice_form = $form['choice_wrapper']['choice']; - unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers. + + // Prevent duplicate wrappers. + unset($choice_form['#prefix'], $choice_form['#suffix']); $output = theme('status_messages') . drupal_render($choice_form); drupal_json(array('status' => TRUE, 'data' => $output)); diff --git a/modules/poll/poll.test b/modules/poll/poll.test index db30e2038..15e3a454f 100644 --- a/modules/poll/poll.test +++ b/modules/poll/poll.test @@ -187,7 +187,7 @@ class PollJSAddChoice extends DrupalWebTestCase { // @TODO: the framework should make it possible to submit a form to a // different URL than its action or the current. For now, we can just force // it. - $this->additionalCurlOptions[CURLOPT_URL] = url('poll/js', array('absolute' => TRUE)); + $this->additionalCurlOptions[CURLOPT_URL] = url('system/ahah', array('absolute' => TRUE)); $this->drupalPost(NULL, $edit, t('More choices')); unset($this->additionalCurlOptions[CURLOPT_URL]); diff --git a/modules/system/system.module b/modules/system/system.module index 4f8e7983b..e3c7acaed 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -408,6 +408,12 @@ function system_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); + $items['system/ahah'] = array( + 'title' => 'AHAH callback', + 'page callback' => 'form_ahah_callback', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); $items['system/timezone'] = array( 'title' => 'Time zone', 'page callback' => 'system_timezone', |