On this page
function form_get_cache
form_get_cache($form_build_id, &$form_state)
Fetches a form from cache.
Related topics
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;
}
}
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!form.inc/function/form_get_cache/7.x