function ConditionConfigure::submitForm

Same name and namespace in other branches
  1. 4.0.x src/Form/ConditionConfigure.php \Drupal\ctools\Form\ConditionConfigure::submitForm()

Form submission handler.

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 FormInterface::submitForm

File

src/Form/ConditionConfigure.php, line 112

Class

ConditionConfigure
Base class for condition configur operations.

Namespace

Drupal\ctools\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $cached_values = $this->tempstore
    ->get($this->tempstore_id)
    ->get($this->machine_name);
  /** @var \Drupal\Core\Condition\ConditionInterface $instance */
  $instance = $form_state->getValue('instance');
  $instance->submitConfigurationForm($form, $form_state);
  $conditions = $this->getConditions($cached_values);
  if ($instance instanceof ContextAwarePluginInterface) {
    /** @var  \Drupal\Core\Plugin\ContextAwarePluginInterface $instance */
    $context_mapping = $form_state->hasValue('context_mapping') ? $form_state->getValue('context_mapping') : [];
    $instance->setContextMapping($context_mapping);
  }
  if ($instance instanceof ConstraintConditionInterface) {
    /** @var  \Drupal\ctools\ConstraintConditionInterface $instance */
    $instance->applyConstraints($this->getContexts($cached_values));
  }
  if ($form_state->hasValue('id')) {
    $conditions[$form_state->getValue('id')] = $instance->getConfiguration();
  }
  else {
    $conditions[] = $instance->getConfiguration();
  }
  $cached_values = $this->setConditions($cached_values, $conditions);
  $this->tempstore
    ->get($this->tempstore_id)
    ->set($this->machine_name, $cached_values);
  [
    $route_name,
    $route_parameters,
  ] = $this->getParentRouteInfo($cached_values);
  $form_state->setRedirect($route_name, $route_parameters);
}