You are here

public function NodeSelection::getMatchingItems in Multi-path autocomplete 8

Returns a list of matching items.

Return value

array An array of path items. Keys are the system paths of the items and values are (safe HTML) titles of the corresponding pages.

Overrides SelectionBase::getMatchingItems

File

lib/Drupal/mpac/Plugin/mpac/selection/NodeSelection.php, line 35
Contains \Drupal\mpac\Plugin\mpac\selection\NodeSelection.

Class

NodeSelection
Provides specific selection functions for nodes.

Namespace

Drupal\mpac\Plugin\mpac\selection

Code

public function getMatchingItems($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  if (!isset($match)) {
    return array();
  }
  $query = $this
    ->buildEntityQuery($match, $match_operator);
  if ($limit > 0) {
    $query
      ->range(0, $limit);
  }
  $result = $query
    ->execute();
  if (empty($result)) {
    return array();
  }
  $matches = array();

  // Load entites.
  $entities = entity_load_multiple('node', $result);
  foreach ($entities as $entity_id => $entity) {
    $matches["node/{$entity_id}"] = check_plain($entity
      ->label());
  }
  return $matches;
}