You are here

public function AdminSettings::hubspotOauthSubmitForm in HubSpot 8

Same name and namespace in other branches
  1. 3.x src/Form/AdminSettings.php \Drupal\hubspot\Form\AdminSettings::hubspotOauthSubmitForm()

Form submission handler for hubspot_admin_settings().

Parameters

array $form: Active form build.

\Drupal\Core\Form\FormStateInterface $form_state: Active form state.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Ajax response.

File

src/Form/AdminSettings.php, line 228

Class

AdminSettings
Hubspot admin settings form.

Namespace

Drupal\hubspot\Form

Code

public function hubspotOauthSubmitForm(array &$form, FormStateInterface $form_state) : RedirectResponse {
  $config = $this
    ->config(static::SETTINGS);
  global $base_url;
  $options = [
    'query' => [
      'client_id' => $config
        ->get('hubspot_client_id'),
      'redirect_uri' => $base_url . Url::fromRoute('hubspot.oauth_connect')
        ->toString(),
      'scope' => $config
        ->get('hubspot_scope'),
    ],
  ];
  $redirect_url = Url::fromUri('https://app.hubspot.com/oauth/authorize', $options)
    ->toString();
  $response = new RedirectResponse($redirect_url);
  $response
    ->send();
  return $response;
}