You are here

public function FieldValidationRuleSetEditForm::fieldValidationRuleSave in Field Validation 8

Submit handler for fieldValidationRule.

File

src/Form/FieldValidationRuleSetEditForm.php, line 216

Class

FieldValidationRuleSetEditForm
Controller for blocktabs edit form.

Namespace

Drupal\field_validation\Form

Code

public function fieldValidationRuleSave($form, FormStateInterface $form_state) {
  $this
    ->save($form, $form_state);

  // Check if this field has any configuration options.
  $field_validation_rule = $this->fieldValidationRuleManager
    ->getDefinition($form_state
    ->getValue('new'));

  // Load the configuration form for this option.
  if (is_subclass_of($field_validation_rule['class'], '\\Drupal\\field_validation\\ConfigurableFieldValidationRuleInterface')) {

    // Remove the destination parameter as it redirects us back to the
    // overview.
    $this
      ->getRequest()->query
      ->remove('destination');
    $form_state
      ->setRedirect('field_validation.field_validation_rule_add_form', [
      'field_validation_rule_set' => $this->entity
        ->id(),
      'field_validation_rule' => $form_state
        ->getValue('new'),
    ], [
      'query' => [
        'weight' => $form_state
          ->getValue('weight'),
      ],
    ]);
  }
  else {
    $field_validation_rule = [
      'id' => $field_validation_rule['id'],
      'data' => [],
      'weight' => $form_state
        ->getValue('weight'),
    ];
    $field_validation_rule_id = $this->entity
      ->addFieldValidationRule($field_validation_rule);
    $this->entity
      ->save();
    if (!empty($tab_id)) {
      $this
        ->messenger()
        ->addMessage($this
        ->t('The rule was successfully added.'));
    }
  }
}