diff --git a/autosave.module b/autosave.module index 03be427..3853337 100644 --- a/autosave.module +++ b/autosave.module @@ -288,6 +288,22 @@ function autosave_restore($form_id, $timestamp) { if ($record) { $form_state = unserialize($record->serialized); + // Manually load include files that the form depends on. Normally this will + // be handled automatically by form_get_cache() (which this code is copied + // from) but if the autosaved data is old enough that the cache_form entry + // is no longer present, it needs to be done manually. + if (!empty($form_state['build_info']['files'])) { + 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; + } + } + } + // Disable the "this form has already been submitted" nonsense by making // Drupal think the form is being rebuilt as part of a multi-step form. $form_state['rebuild'] = TRUE;