public function MenuSelectAutocompleteController::autocomplete in Menu Select 8
Same name and namespace in other branches
- 2.0.x src/Controller/MenuSelectAutocompleteController.php \Drupal\menu_select\Controller\MenuSelectAutocompleteController::autocomplete()
Returns autocomplete content for the given search queries.
Return value
\Symfony\Component\HttpFoundation\JsonResponse A JSON response.
1 string reference to 'MenuSelectAutocompleteController::autocomplete'
File
- src/
Controller/ MenuSelectAutocompleteController.php, line 38
Class
- MenuSelectAutocompleteController
- Defines a controller class with methods for auto complete.
Namespace
Drupal\menu_select\ControllerCode
public function autocomplete($menus, $max_depth, Request $request) {
$keyword = $request->query
->get('q');
$menu_ids = explode(':', $menus);
$matching_links = $this
->getMatchingLinks($keyword, $menu_ids, $max_depth);
$autocomplete = [];
foreach ($matching_links as $key => $label) {
$autocomplete[] = [
'value' => (string) $key,
'label' => $label,
];
}
return new JsonResponse($autocomplete);
}