function nodehierarchy_widgets_autocomplete_parent in Node Hierarchy 7.4
Same name and namespace in other branches
- 6.3 nodehierarchy_widgets/nodehierarchy_widgets.module \nodehierarchy_widgets_autocomplete_parent()
- 6.2 nodehierarchy_widgets/nodehierarchy_widgets.module \nodehierarchy_widgets_autocomplete_parent()
- 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 - Implements hook_menu().
File
- nodehierarchy_widgets/
nodehierarchy_widgets.module, line 49 - 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);
$limit = 100;
foreach ($options as $key => $item) {
if ($limit-- > 0) {
$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(' ▸ ', $trail) . '</span>';
}
$nodes[$item['title'] . ' [nid:' . $item['nid'] . ']'] = $rendered;
}
}
}
drupal_json_output($nodes);
}