You are here

public function ContributeSettingsForm::validateForm in Contribute 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/ContributeSettingsForm.php, line 181

Class

ContributeSettingsForm
Configure contribute settings for this site.

Namespace

Drupal\contribute\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  if ((string) $form_state
    ->getValue('op') === (string) $this
    ->t('Clear') || $form_state
    ->getValue('disable')) {
    return;
  }
  $account_type = $form_state
    ->getValue('account_type');
  $account_id = $form_state
    ->getValue($account_type . '_id');
  $this->contributeManager
    ->setAccountType($account_type);
  $this->contributeManager
    ->setAccountId($account_id);
  $account = $this->contributeManager
    ->getAccount();
  if (!$account['status']) {
    $t_args = [
      '@name' => $account_type === 'individual' ? $this
        ->t('Drupal.org user name') : $this
        ->t('Drupal.org organization name'),
    ];
    $form_state
      ->setErrorByName($account_type . '_id', $this
      ->t('Invalid @name.', $t_args));
  }
}