diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-03-13 06:55:50 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-03-13 06:55:50 +0000 |
commit | 5e32593f3d7c1dd7412e9f918efa3121ff9e6565 (patch) | |
tree | 25896319767e65552e98f7246c89748d9297ab20 /modules | |
parent | 1106db64560976f8baa1e7ebaa45fd7c4917c2e1 (diff) | |
download | brdo-5e32593f3d7c1dd7412e9f918efa3121ff9e6565.tar.gz brdo-5e32593f3d7c1dd7412e9f918efa3121ff9e6565.tar.bz2 |
- Patch #716602 by effulgentsia: refactor ajax_render() and clean up 'ajax' element type.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/book/book.pages.inc | 11 | ||||
-rw-r--r-- | modules/field/field.form.inc | 2 | ||||
-rw-r--r-- | modules/file/file.module | 6 | ||||
-rw-r--r-- | modules/simpletest/tests/ajax_forms_test.module | 28 | ||||
-rw-r--r-- | modules/simpletest/tests/ajax_test.module | 18 | ||||
-rw-r--r-- | modules/system/system.module | 6 |
6 files changed, 32 insertions, 39 deletions
diff --git a/modules/book/book.pages.inc b/modules/book/book.pages.inc index 832e1e3c5..0ff490abd 100644 --- a/modules/book/book.pages.inc +++ b/modules/book/book.pages.inc @@ -237,7 +237,6 @@ function book_form_update() { // Load the form based upon the $_POST data sent via the ajax call. list($form, $form_state) = ajax_get_form(); - $commands = array(); $bid = $_POST['book']['bid']; // Validate the bid. @@ -248,15 +247,9 @@ function book_form_update() { $form['book']['plid'] = _book_parent_select($book_link); form_set_cache($form['values']['form_build_id'], $form, $form_state); - // Build and render the new select element, then return it in JSON format. + // Build the new select element and return it. $form_state = array(); $form = form_builder($form['form_id']['#value'], $form, $form_state); - - $commands[] = ajax_command_replace(NULL, drupal_render($form['book']['plid'])); + return $form['book']['plid']; } - - // @todo: We could and should just return $form['book']['plid'] and skip the - // ajax_command_replace() above. But for now, this provides a test case of - // returning an AJAX commands array. - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); } diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc index a37343b1e..5154f6331 100644 --- a/modules/field/field.form.inc +++ b/modules/field/field.form.inc @@ -397,7 +397,7 @@ function field_add_more_js($form, $form_state) { $field = $field_info['field']; if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) { - ajax_render(array()); + return; } // Navigate to the right element in the the form. diff --git a/modules/file/file.module b/modules/file/file.module index 875d0abbc..49a1b94fa 100644 --- a/modules/file/file.module +++ b/modules/file/file.module @@ -214,7 +214,7 @@ function file_ajax_upload() { drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error'); $commands = array(); $commands[] = ajax_command_replace(NULL, theme('status_messages')); - ajax_render($commands, FALSE); + return array('#type' => 'ajax', '#commands' => $commands, '#header' => FALSE); } list($form, $form_state, $form_id, $form_build_id) = ajax_get_form(); @@ -224,7 +224,7 @@ function file_ajax_upload() { drupal_set_message(t('An unrecoverable error occurred. Use of this form has expired. Try reloading the page and submitting again.'), 'error'); $commands = array(); $commands[] = ajax_command_replace(NULL, theme('status_messages')); - ajax_render($commands, FALSE); + return array('#type' => 'ajax', '#commands' => $commands, '#header' => FALSE); } // Get the current element and count the number of files. @@ -261,7 +261,7 @@ function file_ajax_upload() { $commands = array(); $commands[] = ajax_command_replace(NULL, $output, $settings); - ajax_render($commands, FALSE); + return array('#type' => 'ajax', '#commands' => $commands, '#header' => FALSE); } /** diff --git a/modules/simpletest/tests/ajax_forms_test.module b/modules/simpletest/tests/ajax_forms_test.module index 176f0697d..040a1d9b8 100644 --- a/modules/simpletest/tests/ajax_forms_test.module +++ b/modules/simpletest/tests/ajax_forms_test.module @@ -67,7 +67,7 @@ function ajax_forms_test_simple_form_select_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_html('#ajax_selected_color', $form_state['values']['select']); $commands[] = ajax_command_data('#ajax_selected_color', 'form_state_value_select', $form_state['values']['select']); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -77,7 +77,7 @@ function ajax_forms_test_simple_form_checkbox_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_html('#ajax_checkbox_value', (int)$form_state['values']['checkbox']); $commands[] = ajax_command_data('#ajax_checkbox_value', 'form_state_value_select', (int)$form_state['values']['checkbox']); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } @@ -233,7 +233,7 @@ function ajax_forms_test_advanced_commands_after_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_after($selector, "This will be placed after"); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -242,7 +242,7 @@ function ajax_forms_test_advanced_commands_after_callback($form, $form_state) { function ajax_forms_test_advanced_commands_alert_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_alert("Alert"); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -252,7 +252,7 @@ function ajax_forms_test_advanced_commands_append_callback($form, $form_state) { $selector = '#append_div'; $commands = array(); $commands[] = ajax_command_append($selector, "Appended text"); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -263,7 +263,7 @@ function ajax_forms_test_advanced_commands_before_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_before($selector, "Before text"); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -271,7 +271,7 @@ function ajax_forms_test_advanced_commands_before_callback($form, $form_state) { */ function ajax_forms_test_advanced_commands_changed_callback($form, $form_state) { $commands[] = ajax_command_changed('#changed_div'); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** * AJAX callback for 'changed' with asterisk marking inner div. @@ -279,7 +279,7 @@ function ajax_forms_test_advanced_commands_changed_callback($form, $form_state) function ajax_forms_test_advanced_commands_changed_asterisk_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_changed('#changed_div', '#changed_div_mark_this'); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -291,7 +291,7 @@ function ajax_forms_test_advanced_commands_css_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_css($selector, array('background-color' => $color)); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -302,7 +302,7 @@ function ajax_forms_test_advanced_commands_data_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_data($selector, 'testkey', 'testvalue'); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -311,7 +311,7 @@ function ajax_forms_test_advanced_commands_data_callback($form, $form_state) { function ajax_forms_test_advanced_commands_html_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_html('#html_div', 'replacement text'); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -320,7 +320,7 @@ function ajax_forms_test_advanced_commands_html_callback($form, $form_state) { function ajax_forms_test_advanced_commands_prepend_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_prepend('#prepend_div', "prepended text"); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -329,7 +329,7 @@ function ajax_forms_test_advanced_commands_prepend_callback($form, $form_state) function ajax_forms_test_advanced_commands_remove_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_remove('#remove_text'); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** @@ -338,5 +338,5 @@ function ajax_forms_test_advanced_commands_remove_callback($form, $form_state) { function ajax_forms_test_advanced_commands_restripe_callback($form, $form_state) { $commands = array(); $commands[] = ajax_command_restripe('#restripe_table'); - return array('#type' => 'ajax_commands', '#ajax_commands' => $commands); + return array('#type' => 'ajax', '#commands' => $commands); } diff --git a/modules/simpletest/tests/ajax_test.module b/modules/simpletest/tests/ajax_test.module index 958617041..44c20f515 100644 --- a/modules/simpletest/tests/ajax_test.module +++ b/modules/simpletest/tests/ajax_test.module @@ -13,12 +13,14 @@ function ajax_test_menu() { $items['ajax-test/render'] = array( 'title' => 'ajax_render', 'page callback' => 'ajax_test_render', + 'delivery callback' => 'ajax_deliver', 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); $items['ajax-test/render-error'] = array( 'title' => 'ajax_render_error', - 'page callback' => 'ajax_test_render_error', + 'page callback' => 'ajax_test_error', + 'delivery callback' => 'ajax_deliver', 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); @@ -26,7 +28,7 @@ function ajax_test_menu() { } /** - * Menu callback; Copies $_GET['commands'] into $commands and ajax_render()s that. + * Menu callback; Returns $_GET['commands'] suitable for use by ajax_deliver(). * * Additionally ensures that ajax_render() incorporates JavaScript settings * by invoking drupal_add_js() with a dummy setting. @@ -40,20 +42,16 @@ function ajax_test_render() { // Add a dummy JS setting. drupal_add_js(array('ajax' => 'test'), 'setting'); - // Output AJAX commands and end the request. - ajax_render($commands); + return array('#type' => 'ajax', '#commands' => $commands); } /** - * Menu callback; Invokes ajax_render_error(). - * - * Optionally passes $_GET['message'] to ajax_render_error(). + * Menu callback; Returns AJAX element with #error property set. */ -function ajax_test_render_error() { +function ajax_test_error() { $message = ''; if (!empty($_GET['message'])) { $message = $_GET['message']; } - ajax_render_error($message); + return array('#type' => 'ajax', '#error' => $message); } - diff --git a/modules/system/system.module b/modules/system/system.module index 7d359303f..29a6a2b27 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -290,8 +290,10 @@ function system_element_info() { // HTML page, so we don't provide defaults for #theme or #theme_wrappers. // However, modules can set these properties (for example, to provide an HTML // debugging page that displays rather than executes AJAX commands). - $types['ajax_commands'] = array( - '#ajax_commands' => array(), + $types['ajax'] = array( + '#header' => TRUE, + '#commands' => array(), + '#error' => NULL, ); $types['html_tag'] = array( '#theme' => 'html_tag', |