You are here

function menu_CrumbsMultiPlugin_hierarchy::findParent in Crumbs, the Breadcrumbs suite 7

Same name and namespace in other branches
  1. 7.2 plugins/crumbs.menu.inc \menu_CrumbsMultiPlugin_hierarchy::findParent()

File

plugins/crumbs.menu.inc, line 23

Class

menu_CrumbsMultiPlugin_hierarchy

Code

function findParent($path, $item) {
  $q = db_select('menu_links', 'parent');
  $q
    ->innerJoin('menu_links', 'child', 'parent.mlid = child.plid');
  $q
    ->addExpression('parent.link_path', 'parent_path');
  $q
    ->addExpression('parent.menu_name', 'menu_name');
  $q
    ->condition('child.link_path', $path);

  // Top-level links have higher priority.
  $q
    ->orderBy('parent.depth', 'ASC');

  // Ignore placeholder or separator menu items added by special_menu_items.
  $q
    ->condition('parent.link_path', array(
    '<nolink>',
    '<separator>',
  ), 'NOT IN');

  // Collect candidates for the parent path, keyed by menu name.
  $candidates = array();
  foreach ($q
    ->execute() as $row) {
    if (!isset($candidates[$row->menu_name])) {
      $candidates[$row->menu_name] = $row->parent_path;
    }
  }
  return $candidates;
}