function domain_access_domain_references_alter in Domain Access 8
Implements hook_domain_references_alter().
File
- domain_access/
domain_access.module, line 296 - Domain-based access control for content.
Code
function domain_access_domain_references_alter($query, $account, $context) {
// Restrict domains by editorial assignment.
if ($context['field_type'] != 'editor') {
return;
}
switch ($context['entity_type']) {
case 'node':
if ($account
->hasPermission('publish to any domain')) {
break;
}
elseif ($account
->hasPermission('publish to any assigned domain')) {
if (!empty($account
->get(DomainAccessManagerInterface::DOMAIN_ACCESS_ALL_FIELD)->value)) {
break;
}
$allowed = \Drupal::service('domain_access.manager')
->getAccessValues($account);
$query
->condition('id', array_keys($allowed), 'IN');
}
else {
// Remove all options.
$query
->condition('id', '-no-possible-match-');
}
break;
case 'user':
if ($account
->hasPermission('assign editors to any domain')) {
// Do nothing.
}
elseif ($account
->hasPermission('assign domain editors')) {
if (!empty($account
->get(DomainAccessManagerInterface::DOMAIN_ACCESS_ALL_FIELD)->value)) {
break;
}
$allowed = \Drupal::service('domain_access.manager')
->getAccessValues($account);
$query
->condition('id', array_keys($allowed), 'IN');
}
else {
// Remove all options.
$query
->condition('id', '-no-possible-match-');
}
break;
default:
// No action taken.
break;
}
}