You are here

function domain_domain_references_alter in Domain Access 8

Implements hook_domain_references_alter().

File

domain/domain.module, line 115
Defines a Domain concept for use with Drupal.

Code

function domain_domain_references_alter($query, $account, $context) {

  // Restrict domains by assignment, being sure only to act on the admin field.
  if ($context['field_type'] == 'admin' && $context['entity_type'] == 'user') {
    if ($account
      ->hasPermission('administer domains')) {

      // Do nothing.
    }
    elseif ($account
      ->hasPermission('assign domain administrators')) {
      $allowed = \Drupal::service('domain.element_manager')
        ->getFieldValues($account, DomainInterface::DOMAIN_ADMIN_FIELD);
      $query
        ->condition('id', array_keys($allowed), 'IN');
    }
    else {

      // Remove all options.
      $query
        ->condition('id', '-no-possible-match-');
    }
  }
}