You are here

public function AutocompleteController::autocomplete in Linkit 8.4

Same name and namespace in other branches
  1. 8.5 src/Controller/AutocompleteController.php \Drupal\linkit\Controller\AutocompleteController::autocomplete()

Menu callback for linkit search autocompletion.

Like other autocomplete functions, this function inspects the 'q' query parameter for the string to use to search for suggestions.

Parameters

Request $request: The request.

$linkit_profile_id: The linkit profile id.

Return value

JsonResponse A JSON response containing the autocomplete suggestions.

1 string reference to 'AutocompleteController::autocomplete'
linkit.routing.yml in ./linkit.routing.yml
linkit.routing.yml

File

src/Controller/AutocompleteController.php, line 77
Contains \Drupal\linkit\Controller\AutocompleteController.

Class

AutocompleteController

Namespace

Drupal\linkit\Controller

Code

public function autocomplete(Request $request, $linkit_profile_id) {
  $this->linkitProfile = $this->linkitProfileStorage
    ->load($linkit_profile_id);
  $string = Unicode::strtolower($request->query
    ->get('q'));
  $matches = $this->resultManager
    ->getResults($this->linkitProfile, $string);
  $json_object = new \stdClass();
  $json_object->matches = $matches;
  return new JsonResponse($json_object);
}