You are here

public function SendGridSettingsForm::validateForm in SendGrid Integration 8.2

Same name and namespace in other branches
  1. 8 src/Form/SendGridSettingsForm.php \Drupal\sendgrid_integration\Form\SendGridSettingsForm::validateForm()

Form validation 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 FormBase::validateForm

File

src/Form/SendGridSettingsForm.php, line 125

Class

SendGridSettingsForm
Class SendGridSettingsForm.

Namespace

Drupal\sendgrid_integration\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($this->moduleHandler
    ->moduleExists('key')) {
    parent::validateForm($form, $form_state);
    return;
  }
  $config = $this
    ->config('sendgrid_integration.settings');

  // Check for API secret key. If missing throw error.
  if (empty($config
    ->get('apikey')) && empty($form_state
    ->getValue('sendgrid_integration_apikey'))) {
    $form_state
      ->setError($form['authentication']['sendgrid_integration_apikey'], $this
      ->t('You have not stored an API Secret Key.'));
  }
  parent::validateForm($form, $form_state);
}