You are here

public function ContextFormBase::submitForm in Context 8

Same name and namespace in other branches
  1. 8.4 modules/context_ui/src/Form/ContextFormBase.php \Drupal\context_ui\Form\ContextFormBase::submitForm()
  2. 8.0 modules/context_ui/src/Form/ContextFormBase.php \Drupal\context_ui\Form\ContextFormBase::submitForm()

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides EntityForm::submitForm

File

modules/context_ui/src/Form/ContextFormBase.php, line 116

Class

ContextFormBase

Namespace

Drupal\context_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Save entity values that the built in submit handler cant take care of.
  if ($form_state
    ->hasValue('require_all_conditions')) {
    $this->entity
      ->setRequireAllConditions($form_state
      ->getValue('require_all_conditions'));
  }
  if ($form_state
    ->hasValue('conditions')) {
    $this
      ->handleConditions($form, $form_state);
  }
  if ($form_state
    ->hasValue('reactions')) {
    $this
      ->handleReactions($form, $form_state);
  }

  // If the group is empty set it to the context no group value,
  // otherwise Drupal will save it as an empty string instead.
  if ($form_state
    ->hasValue('group') && empty($form_state
    ->getValue('group'))) {
    $form_state
      ->setValue('group', Context::CONTEXT_GROUP_NONE);
  }

  // Run the default submit method.
  parent::submitForm($form, $form_state);
}