protected function UserSelection::buildEntityQuery in Open Social 10.1.x
Same name in this branch
- 10.1.x modules/social_features/social_private_message/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\social_private_message\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
- 10.1.x modules/social_features/social_profile/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\social_profile\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
Same name and namespace in other branches
- 8.9 modules/social_features/social_private_message/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\social_private_message\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
- 10.3.x modules/social_features/social_private_message/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\social_private_message\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
- 10.0.x modules/social_features/social_private_message/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\social_private_message\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
- 10.2.x modules/social_features/social_private_message/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\social_private_message\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
Builds an EntityQuery to get referenceable entities.
Parameters
string|null $match: (Optional) Text to match the label against. Defaults to NULL.
string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".
array $ids: (Optional) $ids that are coming from an earlier request.
Return value
\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions and sorting applied to it.
Overrides UserSelection::buildEntityQuery
File
- modules/
social_features/ social_private_message/ src/ Plugin/ EntityReferenceSelection/ UserSelection.php, line 24
Class
- UserSelection
- Provides specific access control for the user entity type.
Namespace
Drupal\social_private_message\Plugin\EntityReferenceSelectionCode
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS', array $ids = []) {
/** @var \Drupal\user\RoleStorageInterface $r_storage */
$role_storage = $this->entityTypeManager
->getStorage('user_role');
// Continue if authenticated users has permission to view private messages.
if ($role_storage
->load(RoleInterface::AUTHENTICATED_ID)
->hasPermission('use private messaging system')) {
return parent::buildEntityQuery($match, $match_operator, $ids);
}
// Gets all roles that have permission to view private messages.
/** @var \Drupal\user\RoleInterface[] $all_roles */
$all_roles = $role_storage
->loadMultiple();
$rids = array_keys(array_filter($all_roles, static function ($role) {
return $role
->hasPermission('use private messaging system');
}));
// Gets users IDs that have permission to view private messages.
$uids = $this->entityTypeManager
->getStorage('user')
->getQuery()
->condition('roles', $rids, 'IN')
->condition('uid', $this->currentUser
->id(), '<>')
->execute();
$query = parent::buildEntityQuery($match, $match_operator, $ids);
$query
->condition('uid', $uids, 'IN');
return $query;
}