If you have a taxonomy page (ie, taxonomy/term/1 or some alias for it), by itself it uses the taxonomy name as the title of the page. But as soon as you make a menu that points to the taxonomy page, the menu text becomes the title of the page.

The reason seems to be that there is no call to drupal_set_title($term->name); in taxonomy_term_page(). Drupal 6 *does* have this call, and in d6 the taxonomy pages always use the name of the taxonomy as the page title.

Since this is different behaviour between d6 and d7 I'm calling this a bug not a feature request. If it is a deliberate change, then call it a feature request to have it back the way it was in d6.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

montesq’s picture

Version: 7.0 » 7.x-dev

Same on 7.x-dev
drupal_set_title was removed in the patch #503456: Remove multiple tid and depth handling for core taxonomy paths
It looks like an edge effect of this patch, however, is it really a bug?
I see 2 advantages :
- the title in the menu is the always the same as the title of the page
- You can "override" the name of the page to give a "more friendly" title

RumpledElf’s picture

Its definitely a bug. You can't override the name of the page to give a "more friendly" title at all unless you write your own module to manually set the title on the page, which newbies certainly aren't going to do.

For example, what if your menu says "CATS" but you want your page to be called "My favourite pet cats"? This is currently impossible. You don't always want your taxonomy to have the same name as the menu that it appears in. If you want your taxonomy to match the menu, just change the taxonomy name to match the menu text. If you don't want them to match, you *can't*. Most people have longer titles for pages and shorter titles for menus and it shouldn't be forced on them having the same for both.

Nodes/views/etc can all have their own titles when they are linked to in a menu in d7, taxonomy pages can't. Hence, I consider it a bug.

Damien Tournoud’s picture

This is definitely not by design. The issue is that taxonomy doesn't define a title callback.

Monochrome’s picture

FileSize
1.05 KB

There appears to be multiple problems with the taxonomy titles.

The taxonomy_menu() function is definitely setting a title callback for 'taxonomy/term/%taxonomy_term' to 'taxonomy_term_title'.

This specific issue with this bug report would seem to be rather complicated. If drupal_set_title() isn't called to set a title, Drupal will call menu_get_active_title() when calling drupal_get_title(). The documentation for menu_get_active_title() plainly states it "Get the title of the current page, as determined by the active trail." The active trail being the breadcrumb, gets all of its names from menu link items, and not the menu router items. Unless the current page doesn't have a menu link item, where it will return the router item of the current page instead.

As far as I am concerned, it is a mistake for drupal_get_title() to call menu_get_active_title() as is. Instead it should call a function that properly returns the title from object returned from menu_get_item(). I have attached a patch that adds in a new function menu_get_title() that will return the title of the current page using menu_get_item() instead. I also modified drupal_get_title() to use the new function instead of menu_get_active_title().

There is a second bug however also noticed by giraffian #1049572: Taxonomy pages don't get their title set (html entities display as text) regarding html special characters being converted into entities twice. The first time the get converted is in the taxonomy title callback function taxonomy_term_title(). The second time they are getting converted is in drupal_get_title() function. As I am unsure where the correct location for this to occur is, I've left things as is.

All that said, i'd personally just change the taxonomy module to call drupal_set_title(). According to the documentation (http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/drupal...) that function is called in 64 places and there is no indication that its deprecated.

Monochrome’s picture

Component: taxonomy.module » menu system
Priority: Normal » Major

Found another instance of this occuring in a different module. If you create a menu link to a user profile (i.e user/1), it will change the name of the user displayed in the profile to the name of the menu link item. Menu items don't even need to enabled for the names of the pages to be changed.

This is the admin user profile on one of our sites and is an example of it occuring: http://www.hidden-waters.com/user/1

We have no modules installed except for core. Its an install of Drupal 7.0. It was done by adding a disabled menu link item to the navigation menu (not displayed) with that obviously illegal user name.

My patch in my previous post fixes this. I've changed the component to menu system, as its trivially fixed in it, and the priority as this seem to be a bigger issue than is immediately obvious.

Monochrome’s picture

Title: Taxonomy title is not used when a taxonomy page is in a menu » Menu link title overrides page titles

Playing around a bit more I've found that the titles for admin pages can be overwritten by creating menu entries in the 'Management' menu. Some may consider this a feature, but to me it doesn't seem right. People with the ability to create menu items will be able to cause various pages to be renamed, even if they can't edit those pages, and as mentioned above the menu items don't even need to be enabled. This seems like its a security issue, albeit a rather small one.

This doesn't effect all page types of course. Any page that is generated by a module that calls drupal_set_title(), such as nodes, wont get their title changed.

I changed the issue name to reflect whats really happening.

Monochrome’s picture

Status: Active » Needs review
Monochrome’s picture

Uploading new fixed patch file with correct paths

Status: Needs review » Needs work

The last submitted patch, 1041906_get_menu_title-1.patch, failed testing.

Monochrome’s picture

After checking the patch failures, I'm confused about it. There is a number test of that are checking the page titles and failing because the patch is stopping Drupal from getting the title from the link menu items. One of the tests even tests the title of a user page and another of a taxonomy page that are linked in a menu, and failing even though as far as I am concerned changes made by the patch is the way it should be acting.

I can understand the search tests failing, but only just. With the patch applied the Search Content screen says "Content" and the Search Users screen says "Users" instead both saying "Search" because that is what the link menu item is labeled. Without using the menu link there is no other way to change the title of the search page.

Interestingly enough, there is even more problems with the current behaviour. If I create a new menu and put the Search menu link item in that menu, then the title of the search page becomes 'Home'. This is really really bad. Not only is the name of the page wrong, but there is no way to change it without moving Menu link item into one of the predefined menus. I would consider submitting another bug report about that, but as far as I am concerned its the same issue as this.

So the steps for that problem are
1) Create a new custom menu, or use an existing custom menu
2) Move the search menu item into the custom menu
3) Visit the search page
4) The title of the page will be 'Home' (I'm guessing its failing to create a full breadcrumb trail so cant get the name from it)

Of course it gets even better! If you put a taxonomy page in a custom menu, it grabs its name from the terms title.

So for taxonomy pages you can follow these steps
1) Create a new custom menu, or use an existing custom menu
2) Create a link to a taxonomy page (that isn't linked in other menus) in the custom menu
3) Visit the taxonomy page
4) The title will be the term title (yay!)

Alternatively you get different behaviour following these steps (the initial reported bug)
1) Create a link to a taxonomy page in one of the 'Main menu', 'Navigation' or 'User Menu' menus
2) Visit the taxonomy page
3) The title will be the name from the menu link item (grr!)

I don't think I really need to say that behaviour is seriously messed up. The lack of consistency is dreadful. Drupal 6 did not act like this.

sun’s picture

Title: Menu link title overrides page titles » Taxonomy term menu link title overrides term page title
Version: 7.x-dev » 8.x-dev
Component: menu system » taxonomy.module
Priority: Major » Normal
Issue tags: +Needs backport to D7

Please just simply do what @Damien Tournoud stated earlier, drupal_set_title().

mpotter’s picture

Any progress on this patch? I'm looking for a workaround for D7? I am using the View override for taxonomy term pages and the Title of each view is using the taxonomy term, even if the Title field for the View itself says "None". Right now I'm just hiding this via CSS, but a real fix would be nice.

ctibor-1’s picture

FileSize
410 bytes

Ok, I created this simple patch, but considering I am a programing noob, I don't have courage to stand by it. It just works for me for now. However as I understand it needs to be modified. I don't have time to mess up with git and setting up drupal developement env now, so anyone feel free to adapt this one liner for inclusion.

--- taxonomy.pages.inc  2011-09-13 23:32:50.000000000 +0200
+++ taxonomy.pages.inc  2011-09-13 23:34:43.388610405 +0200
@@ -14,8 +14,6 @@
  *   The page content.
  */
 function taxonomy_term_page($term) {
+  //Added callback to set the right title for the page.
+  drupal_set_title($term->name);
   // Build breadcrumb based on the hierarchy of the term.
   $current = (object) array(
     'tid' => $term->tid,
DamienMcKenna’s picture

FileSize
483 bytes

The patch from #13 with a slightly better comment that adheres to coding standards (that's the only change). This patch applies cleanly to both D7 and D8.

DamienMcKenna’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, fix_taxonomy_term_title.patch, failed testing.

bobodrone’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
479 bytes

I have tried to rewrite the patch format and hope it helps. Im a bit confused with the patch formats.

bobodrone’s picture

Renamed the patch file...

bobodrone’s picture

Assigned: Unassigned » bobodrone
Status: Needs work » Reviewed & tested by the community

the patch from #14 works fine with git apply and solves the problem!

I have a little bit of a core-patching-newbie-question: why should the patchfile contain "_d8" (drupal 8), doesnt the patch skip the testing phase then?
Is that common? I would like to know... :)

Status: Needs review » Needs work

The last submitted patch, use_term_name_as_page_title-1041906-18.patch, failed testing.

couturier’s picture

Status: Needs work » Reviewed & tested by the community

In case this is of interest, I am not an expert on Panels, but I have heard that this module allows page Views to be built and displayed through the use of "contexts," and that Views built in this manner are smart enough to never overwrite the URL of a taxonomy term.

bobodrone’s picture

The reason why the test are failing in #18 is because the Breadcrumb test asserts that the page title IS the same as the menu link title, the very reason this patch exists...
the line 1373 in modules/simpletest/tests/menu.test show:

      // @todo Normally, you'd expect $term->name as page title here.
      $this->assertBreadcrumb($link['link_path'], $trail, $link['link_title'], $tree);

It should be (I think):

      $this->assertBreadcrumb($link['link_path'], $trail, $term->name, $tree);

How do we change this? Patch for the tests first?

sun’s picture

Status: Reviewed & tested by the community » Needs work

Coolio, let's fix and kill that @todo, please. :)

ELC’s picture

Status: Needs work » Needs review
FileSize
1.68 KB

Combine the patch from #18 with the simpletest fix from #22.

Unable to get the simpletests to work locally without error, so hoping testbot does better than me!

ELC’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.68 KB

Same patch applies to D7 without error or warning, but attached one based on the 7.x branch anyway.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x and 7.x. Thanks!

andypost’s picture

Taxonomy should have it's own title callback, the same for forum #148145: "Forums" title is not localized

andypost’s picture

Status: Fixed » Needs review

I think that something wrong with this patch, because taxonomy already has taxonomy_term_title()
and explicit set_title is wrong

EDIT This patch should be different - we need to find the cause why the title is reverted to menu item

andypost’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community
FileSize
642 bytes
662 bytes

Comment of cause should be changed to the same as node_page_view()

andypost’s picture

Also this require a change notice because a lot of sites could use this "feature" which becames deprecated

catch’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Needs review

Please don't mark your own patch RTBC.

Also a change to an inline comment is not a major bug.

calbasi’s picture

Issue tags: +menu, +taxonomy, +views, +title

I suppose this D/ / Views issue is due to this core issue, isn't it?

http://drupal.org/node/1576094

Status: Needs review » Needs work

The last submitted patch, 1041906-term-title-d7.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
Issue tags: +Quick fix
FileSize
683 bytes

Quick re-roll

Garrett Albright’s picture

Version: 8.x-dev » 7.x-dev
Issue summary: View changes

I tried to replicate this in D8 with the following steps (before patching):

  1. Create site with standard install profile
  2. Create term in "Tags" vocab titled "Foo"
  3. Create menu link in "Main navigation" menu titled "Bar" with path "taxonomy/term/1"
  4. Go to taxonomy/term/1 and check the title

…and it was "Foo," not "Bar." I believe this means the problem has since been fixed in Drupal 8, but please let me know if I followed the steps wrong.

Reassigning to Drupal 7.

mgifford’s picture

Status: Needs review » Closed (cannot reproduce)

I went through the same steps for D7. I got foo too so assume we can close this issue.

<link rel="alternate" type="application/rss+xml" title="RSS - Foo" href="http://drupal7.dev/taxonomy/term/1/feed" />
  <title>Foo | Drupal 7</title>

Maybe it should be listed as Closed Fixed....

@andypost post wasn't clear what he was backporting to D7.

David Hernández’s picture

Assigned: bobodrone » Unassigned
Status: Closed (cannot reproduce) » Needs work

As mentioned by @andypost at https://www.drupal.org/node/1041906#comment-5134852 this patch makes useless the taxonomy_term_title used as title callback on the menu entry for the taxonomy pages.

A quick way to test this is to implement a hook_menu_alter and replacing the 'title callback' of the taxonomy term page ('taxonomy/term/%taxonomy_term'). So, not only makes all the taxonomy_term_title function useless. It also breaks any implementation of hook_menu_alter to replace the title of the taxonomy term page.

  • webchick committed 826ae5a on 8.3.x
    Issue #1041906 by Monochrome, bobodrone, ELC, ctibor, DamienMcKenna:...

  • webchick committed 826ae5a on 8.3.x
    Issue #1041906 by Monochrome, bobodrone, ELC, ctibor, DamienMcKenna:...

  • webchick committed 826ae5a on 8.4.x
    Issue #1041906 by Monochrome, bobodrone, ELC, ctibor, DamienMcKenna:...

  • webchick committed 826ae5a on 8.4.x
    Issue #1041906 by Monochrome, bobodrone, ELC, ctibor, DamienMcKenna:...
David_Rothstein’s picture

Status: Needs work » Fixed
  1. The patch to fix the original bug here was committed a long time ago.
  2. The documentation followup in the more recent patches looks like it got fixed already as part of #1067120: Missing hook_taxonomy_term_view() or hook_entity_view() when viewing a term.
  3. Regarding #37, it might be true that this issue made taxonomy_term_title() obsolete, but it never worked correctly to begin with anyway. Title callbacks in hook_menu() are designed and documented to return menu item titles, not page titles. They only get used as page titles as a fallback if nothing else is available. So if you want to guarantee a particular title, you have to use drupal_set_title() for that.

    Also, this issue just made taxonomy terms behave consistently with nodes, so if there's something that needs to change with that it would be a larger issue to address. We may want a followup to fix some of the taxonomy term documentation, though, since it looks like it still incorrectly documents it as being about the page title.

David_Rothstein’s picture

We may want a followup to fix some of the taxonomy term documentation, though, since it looks like it still incorrectly documents it as being about the page title.

I created a followup in the linked issue with a patch to do that.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.