Vocabulary 1 always gets selected

joachim - December 4, 2008 - 13:40
Project:CCK Node Reference ASM Select
Version:5.x-1.0-rc3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I'm not sure what the 'Vocabulary Filters' setting is meant to do, so I unchecked all of them. However, whenever I go back to the settings page for the widget, the last vocab in the list (tried on two different installs) is checked again.

#1

nath - December 4, 2008 - 14:06

Weird, doesn't happen for me. Are you sure you saved after unchecking the option? The module uses standard Drupal functionality for the settings form.

#2

joachim - December 4, 2008 - 17:06

Yes, just tried it again. Save, go back to configure: it comes back every time!

#3

joachim - December 5, 2008 - 10:22

Weird.. can't reproduce it with a new field.

However, this is what is happening with the problem one:

The settings read in, $widget['vocabulary_filters'] is this:
Array
(
[0] => 1
[1] => 0
[5] => 0
[2] => 0
[3] => 0
[4] => 0
)

And the $options array of vocabs is this:
Array
(
[5] => Catalog
[2] => Free tagging
[3] => Location
[4] => Region
[1] => Vocab 1
)

No idea how that 0 array key got in in the first place though!
... or why it's causing the last entry to get a checkmark!

#4

joachim - December 5, 2008 - 10:52
Status:active» needs review

Okay, digging a bit more.

Saving the widget options with no vocabs selected causes this to get stored:

Array
(
[2] => 0
[3] => 0
[1] => 0
[0] => 1
[5] => 0
[4] => 0
)

and the way this setting is used is to check for $vids in the array values rather than see if a key has a true value. So even though it's the 0 key that is set to 1, that counts the same as if the 1 key were set to 1.

Okay, now I CAN reproduce this.
Create the widget, set it to ASM. Set some vocabs, then edit the widget again and unset them. The widget settings array has mysteriously acquired a 0 key.

I think this is actually a bug in CCK.
If you check what's in $form_values in _content_admin_field_submit() at line 1014 of content_admin.inc, you see that thje arrays for BOTH sets of checkboxes have crud in there that shouldn't be there if no checkboxes are selected:

Eg:
[referenceable_types] => Array
(
[1] => 1
[0] => 1
[audio] => 0
[blog] => 0
[civi_event] => 0
[event_series] => 0
[media_image] => 0
[media_page] => 0
[page] => 0
[product] => 0
[story] => 0
[supporter] => 0
[product_tickets] => 0
)

referenceable_types gets away with it because it's looking for strings in the values, so the surplus 0 and 1 keys don't matter.

$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);

With system settings form, there's the array_filter hack (but that has problems of its own: http://drupal.org/node/315176).

A fix for this module however, is to change line 363 to this:

     '#default_value' => isset($widget['vocabulary_filters']) ? array_filter($widget['vocabulary_filters']) : null

#5

joachim - December 5, 2008 - 10:53
Title:last Vocabulary Filters item always gets selected» Vocabulary 1 always gets selected

PS. It's a coincidence that it's the last vocab. It's just that one was number 1 on both the sites I'm using it on ;)

#6

electricmonk - December 6, 2008 - 20:24

@joachim - I can't see any difference between your change and the original code....

#7

joachim - December 7, 2008 - 15:38

I'm running the variable through array_filter.
It may be the latest CVS version of the code has that now, but it wasn't in the rc release I downloaded last week...

 
 

Drupal is a registered trademark of Dries Buytaert.