diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-17 07:12:16 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-17 07:12:16 +0000 |
commit | 25b9f686a626fc5424c36555fe4757cb8114d4ea (patch) | |
tree | 8640840732e7b9ebcdfaf15a37054714696d4c0f /modules/field | |
parent | 55d9463766e08ebaf9aa08955a418e18fd889353 (diff) | |
download | brdo-25b9f686a626fc5424c36555fe4757cb8114d4ea.tar.gz brdo-25b9f686a626fc5424c36555fe4757cb8114d4ea.tar.bz2 |
#544418 by merlinofchaos, sun, drewish, quicksketch, et al: Integrate CTools AJAX framework with Drupal to extend (and replace) existing ahah framework. Everything about AJAX/AHAH is more betterer now.
Diffstat (limited to 'modules/field')
-rw-r--r-- | modules/field/field.form.inc | 26 | ||||
-rw-r--r-- | modules/field/field.test | 15 |
2 files changed, 21 insertions, 20 deletions
diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc index 20998c349..10f687a56 100644 --- a/modules/field/field.form.inc +++ b/modules/field/field.form.inc @@ -190,7 +190,7 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta '#value' => t('Add another item'), // Submit callback for disabled JavaScript. '#submit' => array('field_add_more_submit'), - '#ahah' => array( + '#ajax' => array( 'path' => 'field/js_add_more/' . $bundle_name_url_css . '/' . $field_name_url_css, 'wrapper' => $field_name_url_css . '-wrapper', 'method' => 'replace', @@ -362,13 +362,13 @@ function field_add_more_js($bundle_name, $field_name) { } if ($invalid) { - drupal_json(array('data' => '')); - exit; + ajax_render(array()); } // We don't simply return a new empty widget row to append to existing ones, // because: // - ahah.js won't simply let us add a new row to a table + // @todo ajax.js lets you. :) // - attaching the 'draggable' behavior won't be easy // So we resort to rebuilding the whole table of widgets including the // existing ones, which makes us jump through a few hoops. @@ -428,21 +428,15 @@ function field_add_more_js($bundle_name, $field_name) { foreach ($form_path as $key) { $field_form = $field_form[$key]; } - // Add a div around the new field to receive the ahah effect. - $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); + // Add a DIV around the new field to receive the AJAX effect. + $field_form[$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') . '</div>'; // Prevent duplicate wrapper. unset($field_form['#prefix'], $field_form['#suffix']); - // If a newly inserted widget contains AHAH behaviors, they normally won't - // work because AHAH doesn't know about those - it just attaches to the exact - // form elements that were initially specified in the Drupal.settings object. - // The new ones didn't exist then, so we need to update Drupal.settings - // by ourselves in order to let AHAH know about those new form elements. - $javascript = drupal_add_js(NULL, NULL); - $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, ' . drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) . ');</script>' : ''; - - $output = theme('status_messages') . drupal_render($field_form) . $output_js; - drupal_json(array('status' => TRUE, 'data' => $output)); - exit; + $output = theme('status_messages') . drupal_render($field_form); + + $commands = array(); + $commands[] = ajax_command_replace(NULL, $output); + ajax_render($commands); } diff --git a/modules/field/field.test b/modules/field/field.test index fce0fd8c2..49a1694bf 100644 --- a/modules/field/field.test +++ b/modules/field/field.test @@ -1336,12 +1336,19 @@ class FieldFormTestCase extends DrupalWebTestCase { unset($this->additionalCurlOptions[CURLOPT_URL]); // The response is drupal_json, so we need to undo some escaping. - $response = json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->drupalGetContent())); - $this->assertTrue(is_object($response), t('The response is an object')); - $this->assertIdentical($response->status, TRUE, t('Response status is true')); + $commands = json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->drupalGetContent())); + + // The JSON response will be two AJAX commands. The first is a settings + // command and the second is the replace command. + $settings = reset($commands); + $replace = next($commands); + + $this->assertTrue(is_object($settings), t('The response settings command is an object')); + $this->assertTrue(is_object($replace), t('The response replace command is an object')); + // This response data is valid HTML so we will can reuse everything we have // for HTML pages. - $this->content = $response->data; + $this->content = $replace->data; // Needs to be emptied out so the new content will be parsed. $this->elements = ''; |