function hook_domain_references_alter in Domain Access 8
Alter the list of domains that may be referenced.
Note that this hook does not fire for users with the 'administer domains' permission.
No return value. Modify the $query object via methods.
Parameters
\Drupal\Core\Entity\Query\QueryInterface $query: An entity query prepared by DomainSelection::buildEntityQuery().
\Drupal\Core\Session\AccountInterface $account: The account of the user viewing the reference list.
array $context: A keyed array passing two items:
- entity_type The type of entity (e.g. node, user) that requested the list.
- bundle The entity subtype (e.g. 'article' or 'page').
- field_type The access field group used for this selection. Groups are 'editor' for assigning editorial permissions (as in Domain Access) 'admin' for assigning administrative permissions for a specific domain. Most contributed modules will use 'editor'.
3 functions implement hook_domain_references_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- domain_access_domain_references_alter in domain_access/
domain_access.module - Implements hook_domain_references_alter().
- domain_domain_references_alter in domain/
domain.module - Implements hook_domain_references_alter().
- domain_test_domain_references_alter in domain/
tests/ modules/ domain_test/ domain_test.module - Implements hook_domain_references_alter().
2 invocations of hook_domain_references_alter()
- DomainHookTest::testHookDomainReferencesAlter in domain/
tests/ src/ Kernel/ DomainHookTest.php - Tests domain references alter hook.
- DomainSelection::buildEntityQuery in domain/
src/ Plugin/ EntityReferenceSelection/ DomainSelection.php - Builds an EntityQuery to get referenceable entities.
File
- domain/
domain.api.php, line 132 - API documentation file for Domain module.
Code
function hook_domain_references_alter(\Drupal\Core\Entity\Query\QueryInterface $query, \Drupal\Core\Session\AccountInterface $account, array $context) {
// Remove the default domain from non-admins when editing nodes.
if ($context['entity_type'] == 'node' && $context['field_type'] == 'editor' && !$account
->hasPermission('edit assigned domains')) {
$default = \Drupal::entityTypeManager()
->getStorage('domain')
->loadDefaultId();
$query
->condition('id', $default, '<>');
}
}