Projet

Général

Profil

Révision 42e6daf3

Ajouté par Julien Enselme il y a environ 10 ans

Update drupal 7.26 -> 7.27

Voir les différences:

drupal7/includes/ajax.inc
308 308
 * pulls the form info from $_POST.
309 309
 *
310 310
 * @return
311
 *   An array containing the $form and $form_state. Use the list() function
312
 *   to break these apart:
311
 *   An array containing the $form, $form_state, $form_id, $form_build_id and an
312
 *   initial list of Ajax $commands. Use the list() function to break these
313
 *   apart:
313 314
 *   @code
314
 *     list($form, $form_state, $form_id, $form_build_id) = ajax_get_form();
315
 *     list($form, $form_state, $form_id, $form_build_id, $commands) = ajax_get_form();
315 316
 *   @endcode
316 317
 */
317 318
function ajax_get_form() {
......
331 332
    drupal_exit();
332 333
  }
333 334

  
335
  // When a page level cache is enabled, the form-build id might have been
336
  // replaced from within form_get_cache. If this is the case, it is also
337
  // necessary to update it in the browser by issuing an appropriate Ajax
338
  // command.
339
  $commands = array();
340
  if (isset($form['#build_id_old']) && $form['#build_id_old'] != $form['#build_id']) {
341
    // If the form build ID has changed, issue an Ajax command to update it.
342
    $commands[] = ajax_command_update_build_id($form);
343
    $form_build_id = $form['#build_id'];
344
  }
345

  
334 346
  // Since some of the submit handlers are run, redirects need to be disabled.
335 347
  $form_state['no_redirect'] = TRUE;
336 348

  
......
345 357
  $form_state['input'] = $_POST;
346 358
  $form_id = $form['#form_id'];
347 359

  
348
  return array($form, $form_state, $form_id, $form_build_id);
360
  return array($form, $form_state, $form_id, $form_build_id, $commands);
349 361
}
350 362

  
351 363
/**
......
366 378
 * @see system_menu()
367 379
 */
368 380
function ajax_form_callback() {
369
  list($form, $form_state) = ajax_get_form();
381
  list($form, $form_state, $form_id, $form_build_id, $commands) = ajax_get_form();
370 382
  drupal_process_form($form['#form_id'], $form, $form_state);
371 383

  
372 384
  // We need to return the part of the form (or some other content) that needs
......
379 391
    $callback = $form_state['triggering_element']['#ajax']['callback'];
380 392
  }
381 393
  if (!empty($callback) && function_exists($callback)) {
382
    return $callback($form, $form_state);
394
    $result = $callback($form, $form_state);
395

  
396
    if (!(is_array($result) && isset($result['#type']) && $result['#type'] == 'ajax')) {
397
      // Turn the response into a #type=ajax array if it isn't one already.
398
      $result = array(
399
        '#type' => 'ajax',
400
        '#commands' => ajax_prepare_response($result),
401
      );
402
    }
403

  
404
    $result['#commands'] = array_merge($commands, $result['#commands']);
405

  
406
    return $result;
383 407
  }
384 408
}
385 409

  
......
1210 1234
    'selector' => $selector,
1211 1235
  );
1212 1236
}
1237

  
1238
/**
1239
 * Creates a Drupal Ajax 'update_build_id' command.
1240
 *
1241
 * This command updates the value of a hidden form_build_id input element on a
1242
 * form. It requires the form passed in to have keys for both the old build ID
1243
 * in #build_id_old and the new build ID in #build_id.
1244
 *
1245
 * The primary use case for this Ajax command is to serve a new build ID to a
1246
 * form served from the cache to an anonymous user, preventing one anonymous
1247
 * user from accessing the form state of another anonymous users on Ajax enabled
1248
 * forms.
1249
 *
1250
 * @param $form
1251
 *   The form array representing the form whose build ID should be updated.
1252
 */
1253
function ajax_command_update_build_id($form) {
1254
  return array(
1255
    'command' => 'updateBuildId',
1256
    'old' => $form['#build_id_old'],
1257
    'new' => $form['#build_id'],
1258
  );
1259
}

Formats disponibles : Unified diff