function form_get_cache in Drupal 7
Same name and namespace in other branches
- 6 includes/form.inc \form_get_cache()
Fetches a form from cache.
Related topics
5 calls to form_get_cache()
- ajax_get_form in includes/
ajax.inc - Gets a form submitted via #ajax during an Ajax callback.
- drupal_build_form in includes/
form.inc - Builds and process a form based on a form id.
- FormsFormCacheTestCase::testCacheForm in modules/
simpletest/ tests/ form.test - Tests storing and retrieving the form from cache.
- FormsFormCacheTestCase::testCacheFormCustomExpiration in modules/
simpletest/ tests/ form.test - Tests changing form_cache_expiration.
- form_test_storage_legacy_handler in modules/
simpletest/ tests/ form_test.module - Emulate legacy AHAH-style ajax callback.
File
- includes/
form.inc, line 517 - Functions for form and batch generation and processing.
Code
function form_get_cache($form_build_id, &$form_state) {
if ($cached = cache_get('form_' . $form_build_id, 'cache_form')) {
$form = $cached->data;
global $user;
if (isset($form['#cache_token']) && drupal_valid_token($form['#cache_token']) || !isset($form['#cache_token']) && !$user->uid) {
if ($cached = cache_get('form_state_' . $form_build_id, 'cache_form')) {
// Re-populate $form_state for subsequent rebuilds.
$form_state = $cached->data + $form_state;
// If the original form is contained in include files, load the files.
// @see form_load_include()
$form_state['build_info'] += array(
'files' => array(),
);
foreach ($form_state['build_info']['files'] as $file) {
if (is_array($file)) {
$file += array(
'type' => 'inc',
'name' => $file['module'],
);
module_load_include($file['type'], $file['module'], $file['name']);
}
elseif (file_exists($file)) {
require_once DRUPAL_ROOT . '/' . $file;
}
}
}
// Generate a new #build_id if the cached form was rendered on a cacheable
// page.
if (!empty($form_state['build_info']['immutable'])) {
$form['#build_id_old'] = $form['#build_id'];
$form['#build_id'] = 'form-' . drupal_random_key();
$form['form_build_id']['#value'] = $form['#build_id'];
$form['form_build_id']['#id'] = $form['#build_id'];
unset($form_state['build_info']['immutable']);
}
return $form;
}
}
}