You are here

protected function AddressBookController::filterTypesByViewAccess in Commerce Core 8.2

Filters out profile types that the current user is not allowed to view.

Parameters

\Drupal\profile\Entity\ProfileTypeInterface[] $profile_types: The profile types.

\Drupal\user\UserInterface $owner: The profile owner.

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

Return value

\Drupal\profile\Entity\ProfileTypeInterface[] The filtered profile types.

2 calls to AddressBookController::filterTypesByViewAccess()
AddressBookController::checkOverviewAccess in modules/order/src/Controller/AddressBookController.php
Checks access for the overview page.
AddressBookController::overviewPage in modules/order/src/Controller/AddressBookController.php
Builds the overview page.

File

modules/order/src/Controller/AddressBookController.php, line 335

Class

AddressBookController
Provides the address book UI.

Namespace

Drupal\commerce_order\Controller

Code

protected function filterTypesByViewAccess(array $profile_types, UserInterface $owner, AccountInterface $account = NULL) {
  $storage = $this->entityTypeManager
    ->getStorage('profile');
  $access_control_handler = $this->entityTypeManager
    ->getAccessControlHandler('profile');
  foreach ($profile_types as $profile_type_id => $profile_type) {
    $profile_stub = $storage
      ->create([
      'type' => $profile_type_id,
      'uid' => $owner
        ->id(),
    ]);
    if (!$access_control_handler
      ->access($profile_stub, 'view', $account)) {
      unset($profile_types[$profile_type_id]);
    }
  }
  return $profile_types;
}