protected function FormCache::loadCachedFormState in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Form/FormCache.php \Drupal\Core\Form\FormCache::loadCachedFormState()
- 9 core/lib/Drupal/Core/Form/FormCache.php \Drupal\Core\Form\FormCache::loadCachedFormState()
Loads the cached form state.
Parameters
string $form_build_id: The unique form build ID.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- core/
lib/ Drupal/ Core/ Form/ FormCache.php, line 149
Class
- FormCache
- Encapsulates the caching of a form and its form state.
Namespace
Drupal\Core\FormCode
protected function loadCachedFormState($form_build_id, FormStateInterface $form_state) {
if ($stored_form_state = $this->keyValueExpirableFactory
->get('form_state')
->get($form_build_id)) {
// Re-populate $form_state for subsequent rebuilds.
$form_state
->setFormState($stored_form_state);
// If the original form is contained in include files, load the files.
// @see \Drupal\Core\Form\FormStateInterface::loadInclude()
$build_info = $form_state
->getBuildInfo();
$build_info += [
'files' => [],
];
foreach ($build_info['files'] as $file) {
if (is_array($file)) {
$file += [
'type' => 'inc',
'name' => $file['module'],
];
$this->moduleHandler
->loadInclude($file['module'], $file['type'], $file['name']);
}
elseif (file_exists($file)) {
require_once $this->root . '/' . $file;
}
}
}
}