You are here

public function SquareSettings::submitForm in Commerce Square Connect 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 ConfigFormBase::submitForm

File

src/Form/SquareSettings.php, line 155

Class

SquareSettings

Namespace

Drupal\commerce_square\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('commerce_square.settings');
  $config
    ->set('app_name', $form_state
    ->getValue('app_name'))
    ->set('app_secret', $form_state
    ->getValue('app_secret'))
    ->set('sandbox_app_id', $form_state
    ->getValue('sandbox_app_id'))
    ->set('sandbox_access_token', $form_state
    ->getValue('sandbox_access_token'))
    ->set('production_app_id', $form_state
    ->getValue('production_app_id'));
  $config
    ->save();
  $options = [
    'query' => [
      'client_id' => $config
        ->get('production_app_id'),
      'state' => \Drupal::csrfToken()
        ->get(),
      'scope' => implode(' ', $this->permissionScope),
    ],
  ];
  $url = Url::fromUri('https://connect.squareup.com/oauth2/authorize', $options);
  $form_state
    ->setResponse(new TrustedRedirectResponse($url
    ->toString()));
  parent::submitForm($form, $form_state);
}