public function FormCache::setCache in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Form/FormCache.php \Drupal\Core\Form\FormCache::setCache()
- 9 core/lib/Drupal/Core/Form/FormCache.php \Drupal\Core\Form\FormCache::setCache()
File
- core/lib/Drupal/Core/Form/FormCache.php, line 173
Class
- FormCache
- Encapsulates the caching of a form and its form state.
Namespace
Drupal\Core\Form
Code
public function setCache($form_build_id, $form, FormStateInterface $form_state) {
$expire = Settings::get('form_cache_expiration', 21600);
if (isset($form['#build_id']) && $form['#build_id'] != $form_build_id) {
$this->logger
->error('Form build-id mismatch detected while attempting to store a form in the cache.');
return;
}
if (isset($form)) {
if ($this->currentUser
->isAuthenticated()) {
$form['#cache_token'] = $this->csrfToken
->get();
}
unset($form['#build_id_old']);
$this->keyValueExpirableFactory
->get('form')
->setWithExpire($form_build_id, $form, $expire);
}
if ($data = $form_state
->getCacheableArray()) {
$this->keyValueExpirableFactory
->get('form_state')
->setWithExpire($form_build_id, $data, $expire);
}
}