You are here

public function AjaxController::privateMessageMembersAutocomplete in Private Message 8

Same name and namespace in other branches
  1. 8.2 src/Controller/AjaxController.php \Drupal\private_message\Controller\AjaxController::privateMessageMembersAutocomplete()

Create AJAX response containing usernames for an autocomplete callback.

Return value

\Drupal\Core\Ajax\AjaxResponse The ajax response

Overrides AjaxControllerInterface::privateMessageMembersAutocomplete

1 string reference to 'AjaxController::privateMessageMembersAutocomplete'
private_message.routing.yml in ./private_message.routing.yml
private_message.routing.yml

File

src/Controller/AjaxController.php, line 164

Class

AjaxController
Controller to handle Ajax requests.

Namespace

Drupal\private_message\Controller

Code

public function privateMessageMembersAutocomplete() {
  $response = new AjaxResponse();
  $username = $this->requestStack
    ->getCurrentRequest()
    ->get('username');
  $accounts = $this->privateMessageService
    ->getUsersFromString($username, self::AUTOCOMPLETE_COUNT);
  $user_info = [];
  foreach ($accounts as $account) {
    if ($account
      ->access('view', $this->currentUser)) {
      $user_info[] = [
        'uid' => $account
          ->id(),
        'username' => $account
          ->getDisplayName(),
      ];
    }
  }
  $response
    ->addCommand(new PrivateMessageMembersAutocompleteResponseCommand($username, $user_info));
  return $response;
}