View not showing correctly where term id equals vocab id
Alan D. - March 19, 2008 - 23:48
| Project: | Taxonomy Menu |
| Version: | 5.x-1.03 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Jump to:
Description
After getting some strange view results, I noticed that the following code from the function _taxonomy_menu_page() will ignore the term id if it is the same as the vocab id. (Approx. line 269)
elseif (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_VIEW) {
// Get the last page argument
$tid = explode('/', $_GET['q']);
$tid = db_escape_string(array_pop($tid));
$arguments[] = $vid;
// Only add the Term ID if its not the Vocabulary ID
if ($vid != $tid) {
$arguments[] = $tid;
}Unless there is another reason for this, it would be best to only get the tid from the request iff the request has more than two arguments. I think it would be fairly common for the first added vocab to be used as the tax menu, and this is also likely to have the first term.
My implementation is listed below.
elseif (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_VIEW) {
// Get the last page argument if supplied
$tids = explode('/', $_GET['q']);
$tid = (count($tids) > 2) ? db_escape_string(array_pop($tids)) : FALSE;
$arguments[] = $vid;
// Only add the Term ID if supplied
if ($tid) {
$arguments[] = $tid;
}Regards
Alan

#1
Subscribing
#2
subscribing.
#3
ping:
Is this still valid?
Looks like a simple and pretty harmless change..... but what do I know :)
EDIT:
I marked #221342: Taxonomy Menu and Views lose some content nodes as a duplicate of this issue.
I have noticed quite a few issues regarding this exact piece of code. Does the above fix work? Or, does this section of code just need some better documentation/explanation?
can we kill this once and for all?
#4
This is only applicable for the 5.x-1 branch. It is very easy to duplicate, use a fresh install and add a vocab and a term, then go to that menu path. The term is ignored.
Easy workaround, add a vocab, add a term placeholder term, add a number of real terms, delete the placeholder term, add more vocabs / terms while #terms is always greater than #vocabs. Very unlikely but vocab with vid 4 with a term with tid 4 will produce the same bug.
By the comment in the code Only add the Term ID if its not the Vocabulary ID, it appears to be a misunderstanding of the {vocab}.vid and {term_data}.tid
A quick code read shows
<?php variable_get('taxonomy_menu_hide_module_page', FALSE)); ?>so I'm guessing that the code should be:<?php
elseif (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_VIEW) {
// Get the last page argument if supplied
$tids = explode('/', $_GET['q']);
// TODO: Can 'taxonomy_menu_display_page' produce two or more path items?
$min_term_position = variable_get('taxonomy_menu_hide_module_page', FALSE))
? 2
: count(expode('/', variable_get('taxonomy_menu_display_page', 'category'))) + 2;
$tid = (count($tids) >= $min_term_position) ? db_escape_string(array_pop($tids)) : FALSE;
$arguments[] = $vid;
// Only add the Term ID if supplied
if ($tid) {
$arguments[] = $tid;
}
?>
Totally untested, the code written directly into the comment area after looking at the module code for 5 minutes.