summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/ajax.inc4
-rw-r--r--includes/form.inc31
2 files changed, 33 insertions, 2 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc
index 6a5a25e59..e3e324f82 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -149,7 +149,7 @@ function ajax_render($commands = array(), $header = TRUE) {
*/
function ajax_render_error($error = '') {
$commands = array();
- $commands[] = ajax_command_error(empty($error) ? t('An error occurred while handling the request: The server received invalid input.') : $error);
+ $commands[] = ajax_command_alert(empty($error) ? t('An error occurred while handling the request: The server received invalid input.') : $error);
ajax_render($commands);
}
@@ -301,7 +301,7 @@ function ajax_process_form($element) {
'wrapper' => empty($element['#ajax']['wrapper']) ? NULL : $element['#ajax']['wrapper'],
'selector' => empty($element['#ajax']['selector']) ? '#' . $element['#id'] : $element['#ajax']['selector'],
'effect' => empty($element['#ajax']['effect']) ? 'none' : $element['#ajax']['effect'],
- 'speed ' => empty($element['#ajax']['effect']) ? 'none' : $element['#ajax']['effect'],
+ 'speed' => empty($element['#ajax']['effect']) ? 'none' : $element['#ajax']['effect'],
'method' => empty($element['#ajax']['method']) ? 'replace' : $element['#ajax']['method'],
'progress' => empty($element['#ajax']['progress']) ? array('type' => 'throbber') : $element['#ajax']['progress'],
'button' => isset($element['#executes_submit_callback']) ? array($element['#name'] => $element['#value']) : FALSE,
diff --git a/includes/form.inc b/includes/form.inc
index b57b7c816..0e6221ce7 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -155,6 +155,19 @@ function drupal_build_form($form_id, &$form_state) {
$form_build_id = 'form-' . md5(uniqid(mt_rand(), TRUE));
$form['#build_id'] = $form_build_id;
+ // Record the filepath of the include file containing the original form,
+ // so the form builder callbacks can be loaded when the form is being
+ // rebuilt on a different path (such as 'system/ajax').
+ // @see form_get_cache()
+ // @see drupal_retrieve_form()
+ // menu_get_item() is not available at installation time.
+ if (!defined('MAINTENANCE_MODE')) {
+ $item = menu_get_item();
+ if (!empty($item['file'])) {
+ $form['#include_file'] = $item['file'];
+ }
+ }
+
// Fix the form method, if it is 'get' in $form_state, but not in $form.
if ($form_state['method'] == 'get' && !isset($form['#method'])) {
$form['#method'] = 'get';
@@ -299,6 +312,15 @@ function drupal_rebuild_form($form_id, &$form_state, $form_build_id = NULL) {
function form_get_cache($form_build_id, &$form_state) {
if ($cached = cache_get('form_' . $form_build_id, 'cache_form')) {
$form = $cached->data;
+ // If the original form is contained in an optional include file, load the
+ // file and re-populate $form_state for subsequent rebuilds.
+ // @see drupal_build_form()
+ // @see drupal_retrieve_form()
+ if (!empty($form['#include_file']) && file_exists($form['#include_file'])) {
+ require_once DRUPAL_ROOT . '/' . $form['#include_file'];
+ $form_state['include_file'] = $form['#include_file'];
+ }
+
global $user;
if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) {
if ($cached = cache_get('storage_' . $form_build_id, 'cache_form')) {
@@ -452,6 +474,15 @@ function drupal_retrieve_form($form_id, &$form_state) {
$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);
$form['#form_id'] = $form_id;
$form['#args'] = $form_state['args'];
+
+ // Whenever this form is (re)built, restore the include file property from
+ // $form_state, if existent.
+ // @see drupal_build_form()
+ // @see form_get_cache()
+ if (!empty($form_state['include_file'])) {
+ $form['#include_file'] = $form_state['include_file'];
+ }
+
return $form;
}