function menu_hansel_get_parent in Hansel breadcrumbs 8
Same name and namespace in other branches
- 7 hansel.actions.inc \menu_hansel_get_parent()
Implements hook_hansel_get_parent().
Parameters
string $path :
Return value
array
File
- ./
hansel.actions.inc, line 268 - Hansel breadcrumb actions
Code
function menu_hansel_get_parent($path) {
// Build a list of menu names. We will only look for items in one of these menu's.
$menus = menu_get_menus();
if (isset($menus['devel'])) {
// Do not use the development menu.
unset($menus['devel']);
}
$menus = array_keys($menus);
// Let other modules alter the menu list.
drupal_alter('hansel_menus', $menus);
if ($menus) {
// Try to get parent by menu.
$query = db_select('menu_links', 'c');
$p = $query
->join('menu_links', 'p', 'c.plid = p.mlid');
$link = $query
->fields($p, array(
'link_path',
'link_title',
))
->condition('c.link_path', $path)
->condition('c.menu_name', $menus)
->orderBy("{$p}.depth", 'asc')
->orderBy("{$p}.weight", 'asc')
->range(0, 1)
->execute()
->fetchObject();
if ($link) {
return array(
'path' => $link->link_path,
'title' => $link->link_title,
);
}
}
if (preg_match('/^node\\/([0-9]+)$/si', $path, $match)) {
// Try to get parent by nodetype settings.
$nodetypes = variable_get('hansel_nodetypes', array());
$node = node_load($match[1]);
if (($node = node_load($match[1])) && isset($nodetypes[$node->type])) {
return $nodetypes[$node->type];
}
}
return FALSE;
}