function ConditionForm::submitForm

Overrides ExpressionFormInterface::submitForm

1 call to ConditionForm::submitForm()
ConditionForm::validateForm in src/Form/Expression/ConditionForm.php
Form validation callback to validate expression elements.

File

src/Form/Expression/ConditionForm.php, line 176

Class

ConditionForm
UI form for adding/editing a Rules condition.

Namespace

Drupal\rules\Form\Expression

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    $condition_id = $form_state->get('condition_id');
    // Nothing to do as long as the first step is not completed.
    if (!$condition_id) {
        return;
    }
    $condition_definition = $this->conditionManager
        ->getDefinition($condition_id);
    $context_config = $this->getContextConfigFromFormValues($form_state, $condition_definition['context_definitions']);
    // Rename provided variables, if any.
    if ($provided_variables = $form_state->getValue('provides')) {
        foreach ($provided_variables as $provides_name => $provides_context) {
            // Do this only on rename.
            if ($provides_name !== $provides_context['name']) {
                \Drupal::messenger()->addWarning("providing '" . $provides_name . "' as '" . $provides_context['name'] . "'");
                $context_config->provideAs($provides_name, $provides_context['name']);
            }
        }
    }
    $configuration = $context_config->toArray();
    $configuration['condition_id'] = $form_state->get('condition_id');
    $configuration['negate'] = $form_state->getValue('negate');
    $this->conditionExpression
        ->setConfiguration($configuration);
}