You are here

public function SettingsForm::validateForm in Twitter Profile Widget 8.2

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

Implements form validation.

The validateForm method is the default method called to validate input on a form.

Parameters

array $form: The render array of the currently built form.

\Drupal\Core\Form\FormStateInterface $form_state: Object describing the current state of the form.

Overrides FormBase::validateForm

File

src/Form/SettingsForm.php, line 89

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\twitter_profile_widget\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $twitter = new TwitterProfile();
  $connection = $twitter
    ->checkConnection($values['twitter_widget_key'], $values['twitter_widget_secret']);
  if ($connection === FALSE) {
    $form_state
      ->setErrorByName('twitter_widget_secret', $this
      ->t('Cannot connect to Twitter. Please check the Twitter account and credentials.'));
  }
  if ($connection !== TRUE) {
    $form_state
      ->setErrorByName('twitter_widget_secret', $connection . $this
      ->t('The form has not been updated; any previously valid data you entered will remain active.'));
  }
}