I'm running drupal-7.0-rc2 and have noticed a problem with the breadcrumb trail and title settings on several web pages added by contrib modules (generally on pages added via hook_menu that have type = MENU_CALLBACK). Although the problem is apparent in contrib modules, the responsible bugs are in the core code (in includes/menu.inc), which is why I'm posting this as a core issue.
To reproduce the issue:
- Install the Feeds module, version 7.x-2.0-alpha2
- Enable the "Feeds" and "Feeds Admin UI" modules
- Look at admin/structure/feeds/export/node
Problems on the displayed page:
- The title (both in the browser caption and on the web page) is "Home" instead of "Edit importer: Node import". (The correct title is set via a title_callback, and the title_callback is being called, but the title is then being discarded)
- The breadcrumb trail is simply "Home" instead of "Home » Administration » Structure » Feeds importers"
I've seen these problems with modules other than Feeds, but Feeds was the most convenient for demonstration. The comparable page in Drupal6 has the correct title and correct breadcrumb trail, so effectively the behaviour of the hook_menu API has changed in an undocumented and undesirable way between Drupal6 and Drupal7. Also, FWIW, the visible problems are very similar to those reported in #907690: Breadcrumbs don't work for dynamic paths & local tasks #2 and #925778: User edit title is broken (so is beta1-beta2 upgrade path), but the patches in those issues don't fix these bugs.
I've tracked down the source of the problem and I'm attaching a patch that fixes the problems. As explanation of the changes I've made:
- In menu_set_active_trail, the generated trail must include the current page for the page title to be generated. The previous code did not add the current page if MENU_VISIBLE_IN_BREADCRUMB was false -- but that condition is inappropriate. Even if the page is not displayed in the breadcrumb, it still needs to be added to the trail -- and the code that actually generates the breadcrumb correctly deals with the visible flag.
- In menu_link_get_preferred, the code searches in the menu_links table for relevant entries. In the above example, it's specifically searching for "admin/structure/feeds/export/node" and "admin/structure/feeds/export/%" in menu_links. But for menu items with type = MENU_CALLBACK, they do not have entries in menu_links. In Drupal6, the comparable code worked backwards through the path until it found a match -- searching for "admin/structure/feeds/export" and then "admin/structure/feeds", at which point a match exists. In Drupal7, the code was simply giving up after the first search. I've added a recursive call to menu_link_get_preferred that duplicates the Drupal6 behaviour.
- The menu_link_get_preferred bug fix revealed one more error in menu_set_active_trail. If the preferred_link is set, but that trail does not include the current page, the current page still gets left out of the trail -- because current_item wasn't being used for the tests in the old code.
| Comment | File | Size | Author |
|---|---|---|---|
| hook_menu-missing-breadcrumb-and-title.patch | 1.77 KB | Nephele |
Comments
Comment #1
pillarsdotnet commentedPossibly a dup of #965272: Items defined with type MENU_CALLBACK show "Home" as a title but with a different fix.
Comment #2
sunRight. :)