Hello,

I created a new taxonomy vocabulary called Test. This vocabulary is associated with Blog Entry and has single hierarchy. The terms in Test vocabulary are:

Root1
- Sub1 (parent is Root1)
- Sub2 (parent is Root1)
Root2
- Sub3 (parent is Root2)
Root3

After I enabled this taxonomy Test filter with Views CMS tool (exposed filter with optional, single select), the select box overwrote Root1 with '- None selected -'.

When I traced the code, it looks like $option[''] in function _taxonomy_term_select() in taxonomy.module is causing the problem. Changing it to $option[] solves the problem; however, I would like to share the finding with the community and may be there is something more to it. My solution could be wrong. Our PHP version is 5.2.5

- None selected -
- Sub1
- Sub2
Root2
-Sub3
Root3

Thanks,
Kathy

CommentFileSizeAuthor
#5 321859.patch410 bytesdouggreen

Comments

kathylin’s picture

Project: Drupal core » Views (for Drupal 7)
Version: 5.7 » 5.x-1.6
Component: taxonomy.module » taxonomy data

I did more investigation. It looks the bug is a result of Taxonomy.module and views_taxonomy.inc.

I reverted the change in taxonomy.module and did the following change in views_taxonomy.inc

function views_taxonomy_form(&$vocabulary) {
if ($vocabulary->tags) {
.......
}
else {
.......
if (!$vocabulary->required) {
unset($form['#options']['']); //change from $form['#options'][0] to $form['#options']['']
}
....
}
return $form;
}

therzog’s picture

I got the same problem. It's because starting with drupal 5.4, the "blank" option is keyed with an empty string, not the zero-eth element, so views_taxonomy_form() ends up deleting the 1st actual term instead of the "blank" element. Here is my patch: you don't need to do anything to taxonomy.module:

Index: views_taxonomy.inc
===================================================================
RCS file: /usr/local/cvsroot/wri/mainsite/sites/default/modules/views/modules/views_taxonomy.inc,v
retrieving revision 1.2
diff -u -r1.2 views_taxonomy.inc
--- views_taxonomy.inc  27 May 2008 16:55:54 -0000      1.2
+++ views_taxonomy.inc  24 Oct 2008 20:19:09 -0000
@@ -240,9 +240,7 @@
     $form = taxonomy_form($vocabulary->vid, 0, $vocabulary->help);
     unset($form['#title']);
     unset($form['#description']);
-    if (!$vocabulary->required) {
-      unset($form['#options'][0]);
-    }
+    unset($form['#options']['']);
     unset($form['#default_value']);
     $form['#multiple'] = TRUE;
   }

tanyi’s picture

I tried the above patch but it doesn't work.

levelos’s picture

That patch isn't quite right as the unset needs to be inside the conditional. This should do it. Also note you need to edit/save your view for it to be applied.

Index: modules/views_taxonomy.inc
--- modules/views_taxonomy.inc Base (BASE)
+++ modules/views_taxonomy.inc Locally Modified (Based On LOCAL)
@@ -241,7 +241,7 @@
     unset($form['#title']);
     unset($form['#description']);
     if (!$vocabulary->required) {
-      unset($form['#options'][0]);
+      unset($form['#options']['']);
     }
     unset($form['#default_value']);
     $form['#multiple'] = TRUE;
douggreen’s picture

Status: Active » Needs review
StatusFileSize
new410 bytes

I'm really surprised to discover that this is still a problem in views1, but I think that this is correct.

As this works now (and the way I think it's always worked) is that the exposed taxonomy filter shows:

<All>
- None -
Term2
Term3
Term4
...

After the patch, the exposed taxonomy filter shows:

<All>
Term1
Term2
Term3
Term4
...

I never understood why the "" and "- None -" were both there and formatted differently. It now makes sense. The "" comes from views. And the "- None -" comes from taxonomy, and views intended to remove it.

As far as I can tell the intention of this code was to remove the "- None -" option on vocabulary that isn't required. Required vocabularies are shown on every single node. So, I'm not quite sure what the logic behind this was. I'd think that the "- None -" should always be removed.

I've converted the above to a patch and changed the status of this, so that someone from the views development team might look at it and weigh in. But I don't know if there will ever be another views1release...

douggreen’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of #142347: Not all taxonomy terms showing up in exposed filter and appears to already be fixed in the dev release.