You are here

public function GoogleApiClient::setScopes in Google API PHP Client 8.3

Same name and namespace in other branches
  1. 8.4 src/Entity/GoogleApiClient.php \Drupal\google_api_client\Entity\GoogleApiClient::setScopes()
  2. 8.2 src/Entity/GoogleApiClient.php \Drupal\google_api_client\Entity\GoogleApiClient::setScopes()

Function set Scopes.

Parameters

array $scopes: Pass array of scopes for the account.

Overrides GoogleApiClientInterface::setScopes

File

src/Entity/GoogleApiClient.php, line 270

Class

GoogleApiClient
Defines the GoogleApiClient entity.

Namespace

Drupal\google_api_client\Entity

Code

public function setScopes(array $scopes) {
  $services = $this
    ->getServices();
  $all_scopes = google_api_client_google_services_scopes($services);
  $merged_scopes = [];
  foreach ($scopes as $scope) {
    foreach ($all_scopes as $scopes) {
      if (UrlHelper::isValid($scope, TRUE)) {
        if (in_array($scope, $scopes)) {
          $merged_scopes[] = array_search($scope, $scopes);
          break;
        }
      }
      else {
        if (in_array($scope, array_keys($scopes))) {
          $merged_scopes[] = $scope;
          break;
        }
      }
    }
  }
  return $this
    ->set('scopes', $merged_scopes);
}