You are here

protected function MenuSelectAutocompleteController::getMatchingLinks in Menu Select 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/MenuSelectAutocompleteController.php \Drupal\menu_select\Controller\MenuSelectAutocompleteController::getMatchingLinks()

Get links matching the given keyword.

Parameters

string $keyword: The keyword to search for.

array $menus: An array of menus to search.

int $max_depth: The maximum depth to search.

Return value

array An array of link options matching the keyword.

1 call to MenuSelectAutocompleteController::getMatchingLinks()
MenuSelectAutocompleteController::autocomplete in src/Controller/MenuSelectAutocompleteController.php
Returns autocomplete content for the given search queries.

File

src/Controller/MenuSelectAutocompleteController.php, line 65

Class

MenuSelectAutocompleteController
Defines a controller class with methods for auto complete.

Namespace

Drupal\menu_select\Controller

Code

protected function getMatchingLinks($keyword, array $menus, $max_depth) {
  $options = [];
  foreach ($menus as $menu_name) {
    $tree = $this->treeBuilder
      ->loadMenuTree($menu_name, $max_depth);
    $candidates = [];
    $this
      ->buildCandidateLinks($tree, $menu_name, $candidates);
    foreach ($candidates as $key => $menu_link_label) {
      if (stripos($menu_link_label, $keyword) !== FALSE) {
        $options[$key] = $menu_link_label;
      }
    }
  }
  return $options;
}