You are here

function menu_hansel_get_parent in Hansel breadcrumbs 7

Same name and namespace in other branches
  1. 8 hansel.actions.inc \menu_hansel_get_parent()

Implements hook_hansel_get_parent().

Parameters

string $path:

Return value

array

File

./hansel.actions.inc, line 316
Hansel breadcrumb actions

Code

function menu_hansel_get_parent($path) {
  global $language;

  // 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');
    $parent = $query
      ->join('menu_links', 'p', 'c.plid = p.mlid');
    if (module_exists('i18n_menu')) {
      $query
        ->fields($parent, array(
        'menu_name',
        'mlid',
        'link_path',
        'link_title',
        'language',
      ));
      $query
        ->condition('c.language', array(
        $language->language,
        LANGUAGE_NONE,
      ));
    }
    else {
      $query
        ->fields($parent, array(
        'menu_name',
        'link_path',
        'link_title',
      ));
    }
    $query
      ->condition('c.link_path', $path)
      ->condition('c.menu_name', $menus)
      ->orderBy("{$parent}.depth", 'asc')
      ->orderBy("{$parent}.weight", 'asc')
      ->range(0, 1);
    $link = $query
      ->execute()
      ->fetchObject();
    if ($link) {
      if (module_exists('i18n_menu')) {
        $i18n_mode = i18n_menu_mode($link->menu_name);
      }
      else {
        $i18n_mode = FALSE;
      }
      if ($i18n_mode == '5' && $link->language == LANGUAGE_NONE) {

        // Menu is in "Translate and localise" mode and the menu item is "Language neutral" (translatable).
        $link_title = i18n_string_translate(array(
          'menu',
          'item',
          $link->mlid,
          'title',
        ), $link->link_title, array(
          'langcode' => $language->language,
          'sanitize' => FALSE,
        ));
      }
      else {

        // Menu is in "Fixed language" mode, or item is localized (not in "Language neutral").
        $link_title = $link->link_title;
      }
      return array(
        'path' => $link->link_path,
        'title' => $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;
}