You are here

public function SalesforceAuthProviderPluginBase::save in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 src/SalesforceAuthProviderPluginBase.php \Drupal\salesforce\SalesforceAuthProviderPluginBase::save()
  2. 5.0.x src/SalesforceAuthProviderPluginBase.php \Drupal\salesforce\SalesforceAuthProviderPluginBase::save()

Callback for configuration form after saving config entity.

Parameters

array $form: The configuration form.

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

Overrides SalesforceAuthProviderInterface::save

File

src/SalesforceAuthProviderPluginBase.php, line 175

Class

SalesforceAuthProviderPluginBase
Shared methods for auth providers.

Namespace

Drupal\salesforce

Code

public function save(array $form, FormStateInterface $form_state) {
  if ($form_state
    ->getResponse() instanceof TrustedRedirectResponse) {

    // If we're redirecting off-site, do not proceed with save operation.
    // We'll finish saving form input when we complete the OAuth handshake
    // from Salesforce.
    return FALSE;
  }

  // Initialize identity if token is available.
  if (!$this
    ->hasAccessToken()) {
    return TRUE;
  }
  $token = $this
    ->getAccessToken();
  try {
    $this
      ->refreshIdentity($token);
  } catch (\Exception $e) {
    watchdog_exception('salesforce', $e);
    $this
      ->messenger()
      ->addError($e
      ->getMessage());
    $form_state
      ->disableRedirect();
    return FALSE;
  }
  return TRUE;
}