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.
Comment | File | Size | Author |
---|---|---|---|
#34 | 1041906-term-title-36.patch | 683 bytes | andypost |
#25 | 0001-Issue-1041906-by-ELC-Use-drupal_set_title-in-taxonom-d7.patch | 1.68 KB | ELC |
#24 | 0001-Issue-1041906-by-ELC-Use-drupal_set_title-in-taxonom.patch | 1.68 KB | ELC |
#18 | use_term_name_as_page_title-1041906-18.patch | 479 bytes | bobodrone |
#17 | use_term_name_as_page_title.patch | 479 bytes | bobodrone |
Comments
Comment #1
montesq CreditAttribution: montesq commentedSame 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
Comment #2
RumpledElf CreditAttribution: RumpledElf commentedIts 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.
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is definitely not by design. The issue is that taxonomy doesn't define a title callback.
Comment #4
Monochrome CreditAttribution: Monochrome commentedThere 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.
Comment #5
Monochrome CreditAttribution: Monochrome commentedFound 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.
Comment #6
Monochrome CreditAttribution: Monochrome commentedPlaying 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.
Comment #7
Monochrome CreditAttribution: Monochrome commentedComment #8
Monochrome CreditAttribution: Monochrome commentedUploading new fixed patch file with correct paths
Comment #10
Monochrome CreditAttribution: Monochrome commentedAfter 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.
Comment #11
sunPlease just simply do what @Damien Tournoud stated earlier, drupal_set_title().
Comment #12
mpotter CreditAttribution: mpotter commentedAny 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.
Comment #13
ctibor-1 CreditAttribution: ctibor-1 commentedOk, 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.
Comment #14
DamienMcKennaThe 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.
Comment #15
DamienMcKennaComment #17
bobodrone CreditAttribution: bobodrone commentedI have tried to rewrite the patch format and hope it helps. Im a bit confused with the patch formats.Comment #18
bobodrone CreditAttribution: bobodrone commentedRenamed the patch file...Comment #19
bobodrone CreditAttribution: bobodrone commentedthe 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... :)
Comment #21
couturier CreditAttribution: couturier commentedIn 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.
Comment #22
bobodrone CreditAttribution: bobodrone commentedThe 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:
It should be (I think):
How do we change this? Patch for the tests first?
Comment #23
sunCoolio, let's fix and kill that @todo, please. :)
Comment #24
ELC CreditAttribution: ELC commentedCombine 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!
Comment #25
ELC CreditAttribution: ELC commentedSame patch applies to D7 without error or warning, but attached one based on the 7.x branch anyway.
Comment #26
webchickCommitted and pushed to 8.x and 7.x. Thanks!
Comment #27
andypostTaxonomy should have it's own title callback, the same for forum #148145: "Forums" title is not localized
Comment #28
andypostI 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
Comment #29
andypostComment of cause should be changed to the same as node_page_view()
Comment #30
andypostAlso this require a change notice because a lot of sites could use this "feature" which becames deprecated
Comment #31
catchPlease don't mark your own patch RTBC.
Also a change to an inline comment is not a major bug.
Comment #32
calbasiI suppose this D/ / Views issue is due to this core issue, isn't it?
http://drupal.org/node/1576094
Comment #34
andypostQuick re-roll
Comment #35
Garrett Albright CreditAttribution: Garrett Albright commentedI tried to replicate this in D8 with the following steps (before patching):
…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.
Comment #36
mgiffordI went through the same steps for D7. I got foo too so assume we can close this issue.
Maybe it should be listed as Closed Fixed....
@andypost post wasn't clear what he was backporting to D7.
Comment #37
David Hernández CreditAttribution: David Hernández as a volunteer commentedAs 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.
Comment #42
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedAlso, 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.
Comment #43
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedI created a followup in the linked issue with a patch to do that.