You are here

public function MpacAutocomplete::getMatches in Multi-path autocomplete 8

Get matches for the autocompletion.

Parameters

string $type: The type of data to find (i.e. "path" or "shortcut").

string $string: The string to match.

Return value

array An array containing the matching items.

File

lib/Drupal/mpac/MpacAutocomplete.php, line 47
Contains \Drupal\mpac\MpacAutocomplete.

Class

MpacAutocomplete
Defines a helper class to get mpac autocompletion results.

Namespace

Drupal\mpac

Code

public function getMatches($type, $string) {
  $matches = array();
  $handlers = mpac_get_selection_handlers($type);
  if ($string) {
    $limit = $this->configFactory
      ->get('mpac.autocomplete')
      ->get('items.max');

    // Load results.
    foreach ($handlers as $handler) {
      $matches = array_merge($matches, $handler
        ->getMatchingItems($string, 'CONTAINS', $limit));
    }
  }

  // Allow other modules to alter the list of matches.
  \Drupal::moduleHandler()
    ->alter('mpac_selection_matches', $matches, $type, $string);
  return array_slice($matches, 0, $limit, TRUE);
}