function form_get_cache

7.x form.inc form_get_cache($form_build_id, &$form_state)
6.x form.inc form_get_cache($form_build_id, &$form_state)

Fetches a form from cache.

Related topics

2 calls to form_get_cache()
ajax_get_form in drupal-7.x/includes/ajax.inc
Gets a form submitted via #ajax during an Ajax callback.
drupal_build_form in drupal-7.x/includes/form.inc
Builds and process a form based on a form id.

File

drupal-7.x/includes/form.inc, line 502
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;
          }
        }
      }
      return $form;
    }
  }
}