Example #1
0
 /**
  * Loads the cached form state.
  *
  * @param string $form_build_id
  *   The unique form build ID.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 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;
             }
         }
         // Retrieve the list of previously known safe strings and store it for
         // this request.
         // @todo Ensure we are not storing an excessively large string list
         //   in: https://www.drupal.org/node/2295823
         $build_info += ['safe_strings' => []];
         SafeMarkup::setMultiple($build_info['safe_strings']);
         unset($build_info['safe_strings']);
         $form_state->setBuildInfo($build_info);
     }
 }
Example #2
0
 /**
  * Loads the cached form state.
  *
  * @param string $form_build_id
  *   The unique form build ID.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 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;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setFormState(array $form_state_additions)
 {
     $this->decoratedFormState->setFormState($form_state_additions);
     return $this;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function getCache($form_build_id, FormStateInterface &$form_state)
 {
     if ($form = $this->keyValueExpirableFactory->get('form')->get($form_build_id)) {
         $user = $this->currentUser();
         if (isset($form['#cache_token']) && $this->csrfToken->validate($form['#cache_token']) || !isset($form['#cache_token']) && $user->isAnonymous()) {
             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 form_load_include()
                 $form_state['build_info'] += array('files' => array());
                 foreach ($form_state['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 DRUPAL_ROOT . '/' . $file;
                     }
                 }
                 // Retrieve the list of previously known safe strings and store it
                 // for this request.
                 // @todo Ensure we are not storing an excessively large string list
                 //   in: https://www.drupal.org/node/2295823
                 $form_state['build_info'] += array('safe_strings' => array());
                 SafeMarkup::setMultiple($form_state['build_info']['safe_strings']);
                 unset($form_state['build_info']['safe_strings']);
             }
             return $form;
         }
     }
 }
 /**
  * @covers ::setFormState
  */
 public function testSetFormState()
 {
     $form_state_additions = ['foo' => 'bar'];
     $this->decoratedFormState->setFormState($form_state_additions)->shouldBeCalled();
     $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setFormState($form_state_additions));
 }