You are here

public function SpambotUserspamForm::validateForm in Spambot 8

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/SpambotUserspamForm.php, line 276

Class

SpambotUserspamForm
Settings form to save the configuration for Spambot.

Namespace

Drupal\spambot\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $key_required = !empty($values['report']['nids']) && count(array_filter($values['report']['nids']));
  if ($comments_enabled = $this->moduleHandler
    ->moduleExists('comment')) {
    $key_required = !empty($values['report']['cids']) && count(array_filter($values['report']['cids'])) || $key_required;
  }
  if ($key_required && !$this->config
    ->get('spambot_sfs_api_key')) {
    $form_state
      ->setErrorByName('action', $this
      ->t('To report spammers to www.stopforumspam.com, you need to register for an API key at <a href="http://www.stopforumspam.com">www.stopforumspam.com</a> and enter it into the @page.', [
      '@page' => Link::fromTextAndUrl($this
        ->t('spambot settings'), Url::fromRoute('spambot.settings_form'))
        ->toString(),
    ]));
  }
}