You are here

public function BackgroundImageForm::setFormState in Background Image 8

Same name and namespace in other branches
  1. 2.x src/Form/BackgroundImageForm.php \Drupal\background_image\Form\BackgroundImageForm::setFormState()
  2. 2.0.x src/Form/BackgroundImageForm.php \Drupal\background_image\Form\BackgroundImageForm::setFormState()

Sets the current FormState object.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

Return value

self

File

src/Form/BackgroundImageForm.php, line 639

Class

BackgroundImageForm

Namespace

Drupal\background_image\Form

Code

public function setFormState(FormStateInterface $form_state) {

  // Unfortunately, do to how forms are processed, the triggering element's
  // #submit handlers are only copied and not referenced. This means that
  // if Inline Entity Form embeds this on other forms, the real triggering
  // element's submit handlers are ignored. This simply resets the real
  // triggering element and its #submit handlers.
  $element =& $form_state
    ->getTriggeringElement();
  if ($element && isset($element['#array_parents']) && ($real_element =& NestedArray::getValue($this->form, $element['#array_parents']))) {
    $form_state
      ->setTriggeringElement($real_element);
    $form_state
      ->setSubmitHandlers(isset($real_element['#submit']) ? $real_element['#submit'] : []);
  }
  return $this
    ->traitSetFormState($form_state);
}