Going to aggregator/sources/1/categorize and clicking checkboxes produces the desired result (items are categorizes), but it also produces one of these errors for every checked checkbox:

warning: Invalid argument supplied for foreach() in /var/www/vaster/modules/aggregator/aggregator.module on line 1138.

Comments

joshk’s picture

I was incorrect. It throws four errors no matter how many checkboxes.

joshk’s picture

The error is in aggregator_page_list_submit(). It's running through each form_value and treating them all the same. Here are the form values:

Array
(
    [10] => Array
        (
            [1] => 0
        )

    [9] => Array
        (
            [1] => 0
        )

    [8] => Array
        (
            [1] => 0
        )

    [7] => Array
        (
            [1] => 0
        )

    [6] => Array
        (
            [1] => 0
        )

    [5] => Array
        (
            [1] => 0
        )

    [4] => Array
        (
            [1] => 0
        )

    [3] => Array
        (
            [1] => 0
        )

    [2] => Array
        (
            [1] => 0
        )

    [1] => Array
        (
            [1] => 0
        )

    [op] => Save categories
    [submit] => Save categories
    [form_token] => 481eb02bb02e7988323b4f0d2295e8c4
    [form_id] => aggregator_page_source
)

The last four, of course, are the problem.

Proposed Fix:
My immediate though it just to throw in an additional conditional which checks to see if the value of the form_value is an array. It's also running unneceesary db_queries trying to "DELETE FROM {aggregator_category_item} WHERE iid = 'token'", which isn't really good.

The other option would be to make the form itself a bit smarter and have the iid values in a tree so they could be spidered alone. This is probably better as it's more friendly to future form_alters and the like.

Any thoughts?

joshk’s picture

Possible fixes:

  • Check if value is_array
  • Check if key is_numeric
  • Change aggregator_page_list() to make the $form['items'] element a tree, and only iterate through that

I like the latter the best, and it doesn't seem to cause any problems. However, my first attempt to make it a tree didn't produce the desired results.

joshk’s picture

Version: 5.0-beta2 » 5.x-dev
Status: Active » Needs review
StatusFileSize
new1.05 KB

Ok, I've implemented the #tree solution. I think this is best because:

  • It doesn't break anything.
  • It's better style than running through unrelated form_values and checking their type before processing.
  • It offers better hookability for other modules to implement form_alter and potentially do something interesting with categories, or alternatively to cleanly add additional elements to the categorization form.

This patch was made against HEAD.

mfredrickson’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed at TC Drupal Bug Hunt

This patch works as advertised and I agree with the solution. Wrapping the values inside of a '#tree' protects them from colliding with other elements that are form_altered in later.

+1

rstamm’s picture

StatusFileSize
new999 bytes

Patch solves issue in Drupal 4.7.

Steven’s picture

Version: 5.x-dev » 4.7.x-dev

Tested and verified. Committed to HEAD.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

applied

Anonymous’s picture

Status: Fixed » Closed (fixed)