function FormCache::loadCachedFormState

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/FormCache.php \Drupal\Core\Form\FormCache::loadCachedFormState()
  2. 10 core/lib/Drupal/Core/Form/FormCache.php \Drupal\Core\Form\FormCache::loadCachedFormState()
  3. 11.x 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.

1 call to FormCache::loadCachedFormState()
FormCache::getCache in core/lib/Drupal/Core/Form/FormCache.php
Fetches a form from the cache.

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\Form

Code

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;
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.