You are here

public function SettingsForm::validateForm in Twitter Profile Widget 8

Same name and namespace in other branches
  1. 8.2 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.

FormStateInterface $form_state: Object describing the current state of the form.

Overrides FormBase::validateForm

File

src/Form/SettingsForm.php, line 95

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', $result->errors[0]->message . $this
      ->t('The form has not been updated; any previously valid data you entered will remain active.'));
  }
}