You are here

public function BynderOAuthLogin::access in Bynder 8.3

Same name and namespace in other branches
  1. 8 src/Controller/BynderOAuthLogin.php \Drupal\bynder\Controller\BynderOAuthLogin::access()
  2. 8.2 src/Controller/BynderOAuthLogin.php \Drupal\bynder\Controller\BynderOAuthLogin::access()
  3. 4.0.x src/Controller/BynderOAuthLogin.php \Drupal\bynder\Controller\BynderOAuthLogin::access()

Checks access to oAuth login.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

\Drupal\Core\Access\AccessResultInterface Access result.

1 string reference to 'BynderOAuthLogin::access'
bynder.routing.yml in ./bynder.routing.yml
bynder.routing.yml

File

src/Controller/BynderOAuthLogin.php, line 97

Class

BynderOAuthLogin
Controller for oAuth login.

Namespace

Drupal\bynder\Controller

Code

public function access(AccountInterface $account) {
  if ($this->bynder
    ->hasAccessToken()) {
    return AccessResult::forbidden();
  }
  $browsers = $this
    ->entityTypeManager()
    ->getStorage('entity_browser')
    ->loadMultiple();

  /** @var \Drupal\entity_browser\Entity\EntityBrowser $browser */
  foreach ($browsers as $browser) {
    if ($account
      ->hasPermission('access ' . $browser
      ->id() . ' entity browser pages')) {
      foreach ($browser
        ->getWidgets() as $widget) {
        if ($widget instanceof BynderSearch || $widget instanceof BynderUpload) {
          return AccessResult::allowed();
        }
      }
    }
  }
  return AccessResult::forbidden();
}