function nodehierarchy_widgets_autocomplete_parent in Node Hierarchy 6.2
Same name and namespace in other branches
- 6.3 nodehierarchy_widgets/nodehierarchy_widgets.module \nodehierarchy_widgets_autocomplete_parent()
- 7.4 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 - 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) {
/**
* Drupal 6 ignores "empty" paths when populating page arguments. For
* example, the url "nodehierarchy/autocomplete/parent/page//test" will
* return an array with two elements.
*/
$args = func_get_args();
if (count($args) == 2) {
$string = $exclude;
$exclude = 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(' ▸ ', $trail) . ')</span>';
}
$nodes[$item['title'] . ' [nid:' . $item['nid'] . ']'] = $rendered;
}
}
drupal_json($nodes);
}