FormCache::loadCachedFormState

protected FormCache::loadCachedFormState($form_build_id, FormStateInterface $form_state)

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 148

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;
      }
    }
  }
}
doc_Drupal
2016-10-29 09:15:32
Comments
Leave a Comment

Please login to continue.