You are here

function nodehierarchy_widgets_autocomplete_parent in Node Hierarchy 6.3

Same name and namespace in other branches
  1. 6.2 nodehierarchy_widgets/nodehierarchy_widgets.module \nodehierarchy_widgets_autocomplete_parent()
  2. 7.4 nodehierarchy_widgets/nodehierarchy_widgets.module \nodehierarchy_widgets_autocomplete_parent()
  3. 7.2 nodehierarchy_widgets/nodehierarchy_widgets.module \nodehierarchy_widgets_autocomplete_parent()

Page callback for autocomplete.

1 string reference to 'nodehierarchy_widgets_autocomplete_parent'
nodehierarchy_widgets_menu in nodehierarchy_widgets/nodehierarchy_widgets.module
Implementation of hook_menu

File

nodehierarchy_widgets/nodehierarchy_widgets.module, line 47
Alternative parent selector widgets for Node Hierarchy.

Code

function nodehierarchy_widgets_autocomplete_parent($child_type = NULL, $exclude = NULL, $string = NULL) {
  $nodes = array();
  $length = strlen($string);
  $options = _nodehierarchy_widgets_parent_autocomplete_options($child_type, $exclude, $string);
  foreach ($options as $key => $item) {
    $start = empty($string) ? FALSE : strpos(strtolower($item['title']), strtolower($string));
    if ($start !== FALSE) {
      $rendered = $item['title'];
      $rendered = substr_replace($rendered, '<u>', $start, 0);
      $rendered = substr_replace($rendered, '</u>', $start + $length + 3, 0);
      $trail = _nodehierarchy_widgets_autocomplete_parent_heirarchy_trail($item);
      if (count($trail) > 1) {
        $rendered .= ' <span class="nodehierarchy-autocomplete-trail">(' . implode(' &#9656; ', $trail) . ')</span>';
      }
      $nodes[$item['title'] . ' [nid:' . $item['nid'] . ']'] = $rendered;
    }
  }
  drupal_json($nodes);
}