Commit 77d9ff07 authored by Dries's avatar Dries

- Patch #551694 by effulgentsia, rfay, sun | moshe weitzman, Dries:...

- Patch #551694 by effulgentsia, rfay, sun | moshe weitzman, Dries: standardized the return of status messages in AJAX callbacks.
parent aca54cc1
......@@ -214,14 +214,20 @@ function ajax_form_callback() {
if (function_exists($callback)) {
$html = $callback($form, $form_state);
// If the returned value is a string, assume it is HTML and create
// a command object to return automatically.
// If the returned value is a string, assume it is HTML, add the status
// messages, and create a command object to return automatically. We want
// the status messages inside the new wrapper, so that they get replaced
// on subsequent AJAX calls for the same wrapper.
// @see ajax_command_replace()
if (is_string($html)) {
$commands = array();
$commands[] = ajax_command_replace(NULL, $html);
$commands[] = ajax_command_prepend(NULL, theme('status_messages'));
}
// Otherwise, $html is supposed to be an array of commands, suitable for
// Drupal.ajax, so we pass it on as is.
// Drupal.ajax, so we pass it on as is. In this situation, the callback is
// doing something fancy, so let it decide how to handle status messages
// without second guessing it.
else {
$commands = $html;
}
......@@ -370,6 +376,19 @@ function ajax_command_alert($text) {
* This command is implemented by Drupal.ajax.prototype.commands.insert()
* defined in misc/ajax.js.
*
* When using this command, it is likely that any status messages shall be
* output with the given HTML. In case an AJAX callback returns a HTML string
* instead of an AJAX command structure, ajax_form_callback() automatically
* prepends the returned output with status messages.
* To achieve the same result using an AJAX command structure, the AJAX callback
* may use the following:
* @code
* $commands = array();
* $commands[] = ajax_command_replace(NULL, $output);
* $commands[] = ajax_command_prepend(NULL, theme('status_messages'));
* return $commands;
* @endcode
*
* @param $selector
* A jQuery selector string. If the command is a response to a request from
* an #ajax form element then this value can be NULL.
......
......@@ -362,9 +362,5 @@ function field_add_more_js($form, $form_state) {
$field_form[$langcode][$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($field_form[$langcode][$delta]['#prefix']) ? $field_form[$langcode][$delta]['#prefix'] : '');
$field_form[$langcode][$delta]['#suffix'] = (isset($field_form[$langcode][$delta]['#suffix']) ? $field_form[$langcode][$delta]['#suffix'] : '') . '</div>';
$output = theme('status_messages') . drupal_render($field_form);
$commands = array();
$commands[] = ajax_command_replace(NULL, $output);
ajax_render($commands);
return drupal_render($field_form);
}
......@@ -382,7 +382,7 @@ function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight
function poll_choice_js($form, $form_state) {
$choice_form = $form['choice_wrapper']['choice'];
return theme('status_messages') . drupal_render($choice_form);
return drupal_render($choice_form);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment