You are here

function hook_google_api_client_account_state_alter in Google API PHP Client 8.4

Same name and namespace in other branches
  1. 8.3 google_api_client.api.php \hook_google_api_client_account_state_alter()

Allows other modules to modify the state before authentication.

Developers may state, redirect destination after authentication, or set source or remove default source.

File

./google_api_client.api.php, line 50
Hooks provided by the Google Api Client module.

Code

function hook_google_api_client_account_state_alter(&$state, $google_api_client) {

  // We check the account id and the entity type (entity type is important as
  // Other modules like gauth_user extend the same interface
  // and may have same id.
  if ($google_api_client
    ->getId() == 1 && $google_api_client
    ->getEntityTypeId() == 'google_api_client') {

    // If we want that we don't save authentication with google api client
    // Example is if we use google api client for google sign in.
    $google_api_client_index = array_search('google_api_client', $state['src']);
    unset($state['src'][$google_api_client_index]);

    // If we want to redirect to /user page after authentication
    // Say it's again login with google.
    $state['destination'] = '/user';

    // If we are creating our own module which implements
    // hook_google_api_client_google_response()
    // In this case we can set the source and check this in response handler.
    $state['src'][] = 'my_module';
  }
}