Posted by therzog on March 6, 2008 at 6:03am
Jump to:
| Project: | Primary Term |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
The menu needs to remove [none] when it occurs in the options list, since you add it below. Otherwise you get 2+ [none] choices. Looks like the code was there at some point and got commented out. Here's the patch.
--- primary_term.module 11 Nov 2007 23:02:23 -0000 1.1.1.1
+++ primary_term.module 6 Mar 2008 05:59:44 -0000
@@ -48,9 +48,9 @@
foreach($form['taxonomy'] as $vid => $vocab){
if(in_array($vid, $vids)){
if(is_array($vocab['#options'])){
- if(strlen(trim($vocab['#options']))){
- // not sure why we have the line below. from old days.
- // unset($vocab['#options'][0]);
+ if( !is_object($vocab['#options'][0]) ) {
+ // remove the <none> choice for vocabularies that aren't Required
+ unset($vocab['#options'][0]);
}
$terms = $terms + $vocab['#options'];
}
Comments
#1
In drupal 5.4+, the "none" term is keyed with an empty string, not 0. Use this patch instead:
diff -u -r1.2.2.5 primary_term.module
--- primary_term.module 1 Nov 2007 16:39:43 -0000 1.2.2.5
+++ primary_term.module 16 May 2009 22:46:08 -0000
@@ -88,9 +88,9 @@
foreach($form['taxonomy'] as $vid => $vocab){
if(in_array($vid, $vids)){
if(is_array($vocab['#options'])){
- if(strlen(trim($vocab['#options']))){
- // not sure why we have the line below. from old days.
- // unset($vocab['#options'][0]);
+ if( !is_object($vocab['#options']['']) ){
+ // this is the "- None -" choice for optional taxonomies; delete it
+ unset($vocab['#options']['']);
}
$terms = $terms + $vocab['#options'];
}
#2
This entire section of code needs work, the array addition should be a merge, for example.
If someone wants to create a working patch that gets an RTBC, I'll commit it.
See #287040: terms missing from Primary term select box
and
#239608: Setting primary term to <none> broken
#3
Taken care of when #372809: Using with Hierarchical Select broken was committed.