Hi

Thanks for the great module!

If the parent Link uses it seems to affect the bread crumb trail of the "first child". The parent link does not appear in the trail.

Any idea to solve this?

CommentFileSizeAuthor
#5 missingcrumb.jpg32.61 KBstefan81

Comments

stefan81’s picture

anrikun’s picture

Category: bug » support

As stated on the project page, breadcrumb problems are not an issue of Menu Firstchild but an issue of Drupal itself and the buggy includes/menu.inc file.
http://drupal.org/project/menu_node might help but I cannot say as I have not tested it yet.
You may try to patch menu.inc (see http://drupal.org/node/609542): it worked for me.

stefan81’s picture

Anrikun, thanks for your help.
I applied the patches 1 and 2, but unfortunately they did not help me.

anrikun’s picture

Please can you provide more information about your menu? What you expect etc.

stefan81’s picture

StatusFileSize
new32.61 KB

Thanks for asking.
If I use the breadcrumb is missing for the first page in the menu.

The breadcrumbs show for all other menu items.
And, If I link directly to the first page using the node id instead of .

Would be cool to get the breadcrumbs also visible for the first entry.

anrikun’s picture

Sorry but the attachment alone is not enough for me to understand your problem.
Please add an explanation about this attachment.
Also list your menu's items with hierarchy and write which items have real paths and which items have paths.

stefan81’s picture

Hi,
Just noticed that <firstchild> has been stripped off my posts...

In my example, I am using a menu with four items.
All items use <front> or <firstchild> as link.

- Home (<front>)
- Chronik (<firstchild>)
- Archiv (<firstchild>)
- - - Trilogos Filme < no path (left image)
- - - Verein PSYQ < path visible (right image)
- - - Trilogos Forum < path visible
- English (<firstchild>)

Above you can see that the fist menu item under a <firstchild> won't show a bread crumb path.

anrikun’s picture

In includes/menu.inc, function menu_set_active_trail, try to comment this part this way (around line 1550) :

<?php
    while ($curr) {
      // Terminate the loop when we find the current path in the active trail.
/*
      if ($curr['link']['href'] == $item['href']) {
        $trail[] = $curr['link'];
        $curr = FALSE;
      }
      else {
*/
        // Add the link if it's in the active trail, then move to the link below.
        if ($curr['link']['in_active_trail']) {
          $trail[] = $curr['link'];
          $tree = $curr['below'] ? $curr['below'] : array();
        }
        list($key, $curr) = each($tree);
/*
      }
*/
    }
?>

It should work then.

stefan81’s picture

Thank you, this worked out!

verta’s picture

If this is a good solution, could it be proposed for the main code base?

Just an idea.

anrikun’s picture

How to propose it?

verta’s picture

I think the main code issue queue is here:
http://drupal.org/project/issues/drupal

anrikun’s picture

If you have some time, could you please propose it?
I'm a bit busy at the moment! :-)

verta’s picture

After a little filtering, I found this issue
Active trail isn't set on all menu items pointing to the current path
http://drupal.org/node/609542

Which sounds like the same issue. Maybe?

I'm not set up for testing patches, or I'd test that fix - sorry!

anrikun’s picture

Status: Closed (fixed) » Active

I have just added this to Core's issue queue:
#732370: Go as deep as possible when building the active trail.

anrikun’s picture

Status: Active » Closed (fixed)

This information has been added to project page.
So closing it.

nvaken’s picture

Status: Active » Closed (fixed)

Since I do not want to affect our Drupal core for our multi-site setup, I've made a template.php function which will rebuild the breadcrumb when it notices the last menu item as a link and then add the first child's title. Note that this little snippet will not react to settings in "menu breadcrumb" modules or any in it's kind.

Hope this will help some people out.

function phptemplate_breadcrumb($breadcrumb) {
    $current_breadcrumb = menu_get_active_trail();
    
    $last_crumb = end($current_breadcrumb);
    
    if ($last_crumb['link_path'] == '<firstchild>') {
        // Last item is a link to firstchild, therefor we are missing a crumb.
        
        $result = db_query('SELECT * FROM {menu_links} WHERE menu_name = \'%s\' AND plid = %d ORDER BY weight ASC, link_title ASC', $last_crumb['menu_name'], $last_crumb['mlid']);
        $item = db_fetch_array($result);
        
        // Build up the breadcrumb again.
        $breadcrumb = array();
        foreach ($current_breadcrumb as $v) {
            $breadcrumb[] = l($v['title'], $v['href']);
        }
        $breadcrumb[] = $item['link_title'];
    } 
    if (!empty($breadcrumb)) {
        return '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
    }
}
duaelfr’s picture

I had to fix an issue for one of my clients in which breadcrumb were displaying links to "%3Cfirstchild%3E" under Drupal 6.22 with i18n enabled.
Here is the working code if this can help somebody. Sorry for the mess but it seems to have been built on Zen basis. The useful part starts with "// FIX".

function THEME_breadcrumb($breadcrumb) {
  global $language;

  // Determine if we are to display the breadcrumb.
  $show_breadcrumb = theme_get_setting('THEME_breadcrumb');
  if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {

    // Optionally get rid of the homepage link.
    $show_breadcrumb_home = theme_get_setting('THEME_breadcrumb_home');
    if (!$show_breadcrumb_home) {
      array_shift($breadcrumb);
    }
    
    // FIX : replace <firstchild> with a real link in breadcrumb
    $i = count($breadcrumb);
    $menu_name = variable_get('menu_primary_links_source', 'primary-links');
    $langIsDefault = (language_default() == $language);
    $search = '/' . urlencode('<firstchild>');
    if (!$langIsDefault) { $search = '/' . $language->prefix . $search; }
    while ($i--) {
      if (strpos($breadcrumb[$i], $search) !== false) {
        $url = preg_replace('#^.*href="/(.*?)".*$#', '$1', $breadcrumb[$i+1]);
        if (!$langIsDefault) {
          $url = substr($url, strlen($language->prefix) + 1);
        }
        $srcUrl = drupal_lookup_path('source', $url);
        $sql = "SELECT ml2.link_path FROM {menu_links} ml1 LEFT JOIN {menu_links} ml2 ON ml2.plid = ml1.plid WHERE ml1.link_path = '%s' AND ml1.menu_name = '%s' ORDER BY ml2.weight ASC LIMIT 1";
        $newUrl = url(db_result(db_query($sql, $srcUrl, $menu_name)));
        $breadcrumb[$i] = str_replace($search, $newUrl, $breadcrumb[$i]);
      }
    }

    // Return the breadcrumb with separators.
    if (!empty($breadcrumb)) {
      $breadcrumb_separator = theme_get_setting('THEME_breadcrumb_separator');
      $trailing_separator = $title = '';
      if (theme_get_setting('THEME_breadcrumb_title')) {
        if ($title = drupal_get_title()) {
          $trailing_separator = $breadcrumb_separator;
        }
      }
      elseif (theme_get_setting('THEME_breadcrumb_trailing')) {
        $trailing_separator = $breadcrumb_separator;
      }
      return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>";
    }
  }
  // Otherwise, return an empty string.
  return '';
}