You are here

public function PrivateMessageService::getUsersFromString in Private Message 8

Same name and namespace in other branches
  1. 8.2 src/Service/PrivateMessageService.php \Drupal\private_message\Service\PrivateMessageService::getUsersFromString()

Get a list of User objects whose account names begin with the given string.

Only accounts that have 'Use private messaging system' permission will be returned, and the viewing user must have both 'View user information' and 'access user profiles' to get any results at all.

Parameters

string $string: The string to search for.

int $count: The maximum number of results to return.

Return value

\Drupal\user\Entity\User[] An array of User accounts whose account names begin with the given string.

Overrides PrivateMessageServiceInterface::getUsersFromString

File

src/Service/PrivateMessageService.php, line 229

Class

PrivateMessageService
The Private Message service for the private message module.

Namespace

Drupal\private_message\Service

Code

public function getUsersFromString($string, $count) {
  $user_ids = $this->mapper
    ->getUserIdsFromString($string, $count);
  $accounts = [];
  if (count($user_ids)) {
    $accounts = $this->userManager
      ->loadMultiple($user_ids);
  }
  return $accounts;
}