Commit 6393d403 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3268008 by RenatoG: Create the formValidate and formSubmit to SettingsForm

parent d8c56578
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -64,4 +64,41 @@ class BlockClassSettingsForm extends ConfigFormBase {
    return $form;

  }

  /**
   * Validate the maxlength field.
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {

    parent::validateForm($form, $form_state);

    // Get the maxlength_block_class_field field.
    $maxlength_block_class_field = $form_state->getValue('maxlength_block_class_field');

    // Verify if is a positive value.
    if ($maxlength_block_class_field < 1) {
      $form_state->setErrorByName('maxlength_block_class_field', $this->t('The maxlength should be an positive value'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    // Get the maxlength_block_class_field field.
    $maxlength_block_class_field = $form_state->getValue('maxlength_block_class_field');

    // Get the config object.
    $config = $this->config('block_class.settings');

    // Set the value.
    $config->set('maxlength_block_class_field', $maxlength_block_class_field);

    // Save that.
    $config->save();

    parent::submitForm($form, $form_state);
  }

}