summaryrefslogtreecommitdiff
path: root/includes/ajax.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-09-21 08:54:57 +0000
committerDries Buytaert <dries@buytaert.net>2009-09-21 08:54:57 +0000
commit77d9ff0706304cae9f51bd2d514782ba8b488883 (patch)
tree3b6ded3889e11e5c7a4d3fd2feee867fdb9ffb22 /includes/ajax.inc
parentaca54cc198f64e9ef5df8bd5e75aacd1d2669c0b (diff)
downloadbrdo-77d9ff0706304cae9f51bd2d514782ba8b488883.tar.gz
brdo-77d9ff0706304cae9f51bd2d514782ba8b488883.tar.bz2
- Patch #551694 by effulgentsia, rfay, sun | moshe weitzman, Dries: standardized the return of status messages in AJAX callbacks.
Diffstat (limited to 'includes/ajax.inc')
-rw-r--r--includes/ajax.inc25
1 files changed, 22 insertions, 3 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc
index dca3cc76e..8aa7471e5 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -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.