You are here

public function FacebookAlbumForm::validateForm in Facebook Album 8

Call Facebook and get an access token for the given app

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

Overrides FormBase::validateForm

File

src/Form/FacebookAlbumForm.php, line 107
Contains \Drupal\facebook_album\Form\FacebookAlbumForm.

Class

FacebookAlbumForm
Configure facebook_album settings for this site.

Namespace

Drupal\facebook_album\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $app_id = $form_state
    ->getValue('app_id');
  $app_secret = $form_state
    ->getValue('app_secret');
  $auth_path = FACEBOOK_ALBUM_API_AUTH_PATH . 'access_token';
  $parameters = [
    'client_id' => $app_id,
    'client_secret' => $app_secret,
    'grant_type' => 'client_credentials',
  ];
  $response = $this->facebook_album
    ->get($auth_path, $parameters);
  if (isset($response['error'])) {
    $message = $this->facebook_album
      ->translate_error($response['error']['code'], $response['error']['message']);
    $form_state
      ->setErrorByName('app_secret', $message);
  }
  else {
    $form_state
      ->setValue('access_token', $response['access_token']);
  }
  parent::validateForm($form, $form_state);
}