You are here

public function AddressBookAccessCheck::access in Commerce Core 8.2

Checks address book access.

Ensures that the user is logged in, and the address book UI is exposed.

Parameters

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

modules/order/src/Access/AddressBookAccessCheck.php, line 47

Class

AddressBookAccessCheck
Checks address book access.

Namespace

Drupal\commerce_order\Access

Code

public function access(AccountInterface $account) {
  if ($account
    ->isAnonymous()) {

    // Anonymous users can't have an address book.
    return AccessResult::forbidden()
      ->addCacheContexts([
      'user.roles:authenticated',
    ]);
  }
  if (!$this->addressBook
    ->hasUi()) {

    // No UI available.
    return AccessResult::forbidden()
      ->addCacheTags([
      'config:profile_type_list',
    ]);
  }
  return AccessResult::allowed();
}