function domain_entity_get_user_available_domains in Domain Access Entity 8
Same name and namespace in other branches
- 7 domain_entity.module \domain_entity_get_user_available_domains()
Return a list of domain id's, accessible by the current user.
Parameters
\Drupal\Core\Session\AccountInterface $account: Drupal user account.
Return value
array List of domain id's.
1 call to domain_entity_get_user_available_domains()
- domain_entity_query_alter in ./
domain_entity.module - Implements hook_query_alter().
File
- ./
domain_entity.module, line 147 - Enables domain access for entities, and access query alter.
Code
function domain_entity_get_user_available_domains(AccountInterface $account = NULL) {
if (!isset($account)) {
$account = \Drupal::currentUser();
}
// Get the current user list of granted domain id:
// the current domain id OR for middle-office editors:
// the list of assigned domain(s) id.
$current_domain = domain_entity_get_domain();
$accessible_domain_ids = [
$current_domain
->id(),
];
// Middle office editors with permission see in administration,
// entity from her lists of assigned domains.
$route = \Drupal::routeMatch()
->getRouteObject();
$is_admin = \Drupal::service('router.admin_context')
->isAdminRoute($route);
if ($is_admin && $account
->hasPermission('access entities affiliate on assigned domains')) {
$user_domain = domain_entity_get_user_domains($account);
$accessible_domain_ids = !empty($user_domain) ? $user_domain : $accessible_domain_ids;
}
return $accessible_domain_ids;
}