You are here

public function TwitterApiForm::submitForm in Heartbeat 8

Form submission 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 FormInterface::submitForm

File

modules/statusmessage/src/Form/TwitterApiForm.php, line 109

Class

TwitterApiForm
Class TwitterApiForm.

Namespace

Drupal\statusmessage\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Display result.
  foreach ($form_state
    ->getValues() as $key => $value) {
    drupal_set_message($key . ': ' . $value);
  }
  if ($this->statusTwitter === null) {
    $this->statusTwitter = new StatusTwitter();
  }
  if ($form_state
    ->getValue('oauth_access_token')) {
    $this->twitterConfig
      ->set('consumer_key', $form_state
      ->getValue('consumer_key'))
      ->save();
    $this->twitterConfig
      ->set('consumer_secret', $form_state
      ->getValue('consumer_secret'))
      ->save();
    $this->twitterConfig
      ->set('oauth_access_token', $form_state
      ->getValue('oauth_access_token'))
      ->save();
    $this->twitterConfig
      ->set('oauth_access_token_secret', $form_state
      ->getValue('oauth_access_token_secret'))
      ->save();
    \Drupal::logger('statusmessageTwitterAPI')
      ->debug('This is my token: %token', array(
      '%token' => $form_state
        ->getValue('oauth_access_token'),
    ));
  }
}