You are here

function _og_menu_autocomplete in Organic Groups Menu (OG Menu) 7.3

Same name and namespace in other branches
  1. 7.2 og_menu.module \_og_menu_autocomplete()

Retrieve auto-complete suggestions for organic groups.

1 string reference to '_og_menu_autocomplete'
og_menu_menu in ./og_menu.module
Implements hook_menu().

File

./og_menu.module, line 1192
Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.

Code

function _og_menu_autocomplete($string) {
  $matches = array();
  $query = db_select('node', 'n');
  $query
    ->distinct();
  $query
    ->join('og_membership', 'og', 'n.nid = og.gid');
  $query
    ->fields('og', array(
    'gid',
  ));
  $query
    ->fields('n', array(
    'title',
  ));
  $query
    ->condition('n.title', '%' . db_like($string) . '%', 'LIKE');
  $query
    ->range(0, 10);
  $return = $query
    ->execute();
  foreach ($return as $row) {
    $matches[$row->title . " [gid:{$row->gid}]"] = '<div class="og-autocomplete">' . $row->title . '</div>';
  }

  // Return for json.
  drupal_json_output($matches);
}