You are here

protected function FormCache::loadCachedFormState in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 153
Contains \Drupal\Core\Form\FormCache.

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 += array(
          'type' => 'inc',
          'name' => $file['module'],
        );
        $this->moduleHandler
          ->loadInclude($file['module'], $file['type'], $file['name']);
      }
      elseif (file_exists($file)) {
        require_once $this->root . '/' . $file;
      }
    }
  }
}