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.

Comments

nath’s picture

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.

joachim’s picture

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

joachim’s picture

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!

joachim’s picture

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
joachim’s picture

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 ;)

electricmonk’s picture

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

joachim’s picture

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...