You are here

function _mpac_get_matches_for_nodes in Multi-path autocomplete 7

Helper function to find all nodes containing the given title.

Parameters

$title: The title to search for.

1 call to _mpac_get_matches_for_nodes()
mpac_autocomplete in ./mpac.module
Find nodes, shortcuts and URL aliases based on title.

File

./mpac.module, line 156
Find node paths on menu item creation via autocomplete.

Code

function _mpac_get_matches_for_nodes($title = '') {
  $matches = array();
  if ($title == '') {
    return $matches;
  }
  $query = db_select('node', 'n')
    ->extend('PagerDefault');
  $query
    ->condition('title', '%' . $title . '%', 'LIKE');
  $result = $query
    ->fields('n')
    ->limit(variable_get('mpac_max_items', 20))
    ->execute();
  foreach ($result as $node) {

    // Add node path and title to list.
    if (node_access('view', $node) && $node->status) {
      $matches['node/' . $node->nid] = check_plain($node->title);
    }
  }
  return $matches;
}