Révision 42e6daf3
Ajouté par Julien Enselme il y a environ 10 ans
drupal7/includes/form.inc | ||
---|---|---|
168 | 168 |
* processed. |
169 | 169 |
* - base_form_id: Identification for a base form, as declared in a |
170 | 170 |
* hook_forms() implementation. |
171 |
* - immutable: If this flag is set to TRUE, a new form build id is |
|
172 |
* generated when the form is loaded from the cache. If it is subsequently |
|
173 |
* saved to the cache again, it will have another cache id and therefore |
|
174 |
* the original form and form-state will remain unaltered. This is |
|
175 |
* important when page caching is enabled in order to prevent form state |
|
176 |
* from leaking between anonymous users. |
|
171 | 177 |
* - rebuild_info: Internal. Similar to 'build_info', but pertaining to |
172 | 178 |
* drupal_rebuild_form(). |
173 | 179 |
* - rebuild: Normally, after the entire form processing is completed and |
... | ... | |
459 | 465 |
$form = drupal_retrieve_form($form_id, $form_state); |
460 | 466 |
|
461 | 467 |
// If only parts of the form will be returned to the browser (e.g., Ajax or |
462 |
// RIA clients), re-use the old #build_id to not require client-side code to
|
|
463 |
// manually update the hidden 'build_id' input element.
|
|
468 |
// RIA clients), or if the form already had a new build ID regenerated when it
|
|
469 |
// was retrieved from the form cache, reuse the existing #build_id.
|
|
464 | 470 |
// Otherwise, a new #build_id is generated, to not clobber the previous |
465 | 471 |
// build's data in the form cache; also allowing the user to go back to an |
466 | 472 |
// earlier build, make changes, and re-submit. |
467 | 473 |
// @see drupal_prepare_form() |
468 |
if (isset($old_form['#build_id']) && !empty($form_state['rebuild_info']['copy']['#build_id'])) { |
|
474 |
$enforce_old_build_id = isset($old_form['#build_id']) && !empty($form_state['rebuild_info']['copy']['#build_id']); |
|
475 |
$old_form_is_mutable_copy = isset($old_form['#build_id_old']); |
|
476 |
if ($enforce_old_build_id || $old_form_is_mutable_copy) { |
|
469 | 477 |
$form['#build_id'] = $old_form['#build_id']; |
478 |
if ($old_form_is_mutable_copy) { |
|
479 |
$form['#build_id_old'] = $old_form['#build_id_old']; |
|
480 |
} |
|
470 | 481 |
} |
471 | 482 |
else { |
483 |
if (isset($old_form['#build_id'])) { |
|
484 |
$form['#build_id_old'] = $old_form['#build_id']; |
|
485 |
} |
|
472 | 486 |
$form['#build_id'] = 'form-' . drupal_random_key(); |
473 | 487 |
} |
474 | 488 |
|
... | ... | |
523 | 537 |
} |
524 | 538 |
} |
525 | 539 |
} |
540 |
// Generate a new #build_id if the cached form was rendered on a cacheable |
|
541 |
// page. |
|
542 |
if (!empty($form_state['build_info']['immutable'])) { |
|
543 |
$form['#build_id_old'] = $form['#build_id']; |
|
544 |
$form['#build_id'] = 'form-' . drupal_random_key(); |
|
545 |
$form['form_build_id']['#value'] = $form['#build_id']; |
|
546 |
$form['form_build_id']['#id'] = $form['#build_id']; |
|
547 |
unset($form_state['build_info']['immutable']); |
|
548 |
} |
|
526 | 549 |
return $form; |
527 | 550 |
} |
528 | 551 |
} |
... | ... | |
535 | 558 |
// 6 hours cache life time for forms should be plenty. |
536 | 559 |
$expire = 21600; |
537 | 560 |
|
561 |
// Ensure that the form build_id embedded in the form structure is the same as |
|
562 |
// the one passed in as a parameter. This is an additional safety measure to |
|
563 |
// prevent legacy code operating directly with form_get_cache and |
|
564 |
// form_set_cache from accidentally overwriting immutable form state. |
|
565 |
if ($form['#build_id'] != $form_build_id) { |
|
566 |
watchdog('form', 'Form build-id mismatch detected while attempting to store a form in the cache.', array(), WATCHDOG_ERROR); |
|
567 |
return; |
|
568 |
} |
|
569 |
|
|
538 | 570 |
// Cache form structure. |
539 | 571 |
if (isset($form)) { |
540 | 572 |
if ($GLOBALS['user']->uid) { |
541 | 573 |
$form['#cache_token'] = drupal_get_token(); |
542 | 574 |
} |
575 |
unset($form['#build_id_old']); |
|
543 | 576 |
cache_set('form_' . $form_build_id, $form, 'cache_form', REQUEST_TIME + $expire); |
544 | 577 |
} |
545 | 578 |
|
546 | 579 |
// Cache form state. |
580 |
if (variable_get('cache', 0) && drupal_page_is_cacheable()) { |
|
581 |
$form_state['build_info']['immutable'] = TRUE; |
|
582 |
} |
|
547 | 583 |
if ($data = array_diff_key($form_state, array_flip(form_state_keys_no_cache()))) { |
548 | 584 |
cache_set('form_state_' . $form_build_id, $data, 'cache_form', REQUEST_TIME + $expire); |
549 | 585 |
} |
Formats disponibles : Unified diff
Update drupal 7.26 -> 7.27