UserSelection.php in Open Social 10.0.x
File
modules/social_features/social_private_message/src/Plugin/EntityReferenceSelection/UserSelection.php
View source
<?php
namespace Drupal\social_private_message\Plugin\EntityReferenceSelection;
use Drupal\social_profile\Plugin\EntityReferenceSelection\UserSelection as UserSelectionBase;
use Drupal\user\RoleInterface;
class UserSelection extends UserSelectionBase {
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS', array $ids = []) {
$role_storage = $this->entityTypeManager
->getStorage('user_role');
if ($role_storage
->load(RoleInterface::AUTHENTICATED_ID)
->hasPermission('use private messaging system')) {
return parent::buildEntityQuery($match, $match_operator, $ids);
}
$all_roles = $role_storage
->loadMultiple();
$rids = array_keys(array_filter($all_roles, static function ($role) {
return $role
->hasPermission('use private messaging system');
}));
$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;
}
}
Classes
Name |
Description |
UserSelection |
Provides specific access control for the user entity type. |