When creating content and hitting Preview I get this warning:

warning: Invalid argument supplied for foreach() in /home/prkos/public_html/drupal/modules/taxonomy/taxonomy.module on line 70.

Saving the node goes without errors. The node in question has the option to select a taxonomy term from a predefined multiselect list. If I untick the Publish checkbox and then hit Preview there is no warning.

CommentFileSizeAuthor
#28 invalid-arg-520490-28.patch624 bytesdstol
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

qpal’s picture

I am having the exact same problem here.

aasarava’s picture

If you're using Taxonomy Super Select, it looks like the problem is with that module. Here's a link to a patch that worked for me:
http://drupal.org/node/326614#comment-1729860

portulaca’s picture

I'm not using Taxonomy super select, I do have Taxonomy image, I'll test to see if it makes a difference.

lewisheadden’s picture

This seems to be caused (in my situation) by line 55 which checks for an empty array but does not expect the array to contain an empty string as key and value. I believe that multiple select taxonomy boxes are allowing the "-None-" value to be passed as such into the node preview and then causing this error to occur.

Changing line 55 of taxonomy.module from

if (!empty($node->taxonomy)) {

to

if (!empty($node->taxonomy) && array_shift($node->taxonomy) > "") {

seems to fix the problem, however, may not be the cleanest solution.

The root of the cause lies in taxonomy_preview_terms which converts the raw data from $node->taxonomy into Term objects. The line 585 which fetches the term into the $node->taxonomy should check to see if a term ID has been provided otherwise the blank key/value pair get assigned.

I'd be interested to hear some other opinions on it and get a patch together as this seems to be a fault in the Drupal Core.

Cheers,
Lewis

el7cosmos’s picture

The error message has gone, but there's a problem in term links.

Now my node didn't display all of their terms in term links.

Lanae’s picture

I have this error, regardless of whether I enable Taxonomy Super Select.

In addition to the error, I can't add terms to existing nodes. When editing an existing node and selecting a vocabulary term that wasn't selected before, then hitting either preview or publish, the newly-associated term isn't associated with the node. (ie doesn't show up in term links, and when try to edit the node again, new term isn't selected in vocab field.

skizzo’s picture

I am seeing the same problem (no Taxonomy Super Select either). After clicking on "none" in the drop-down select list (term not required) the preview will cause the listed error.

dogbertdp’s picture

I'm also experiencing this issue. Has anyone tried the suggestion in #4? Is it a good approach?

Thanks,
Mike Hays

Lanae’s picture

The best I could tell, in my case, it only happened when using the Bibliography module with CCK taxonomy fields - at least when I stopped using the two together I haven't seen the warning again. So far I've managed to refrain from hacking core.

ressa’s picture

The same happens for me: When I create a new node, everything goes fine, but I get this warning in the log, six times:
Invalid argument supplied for foreach() in /var/www/website/modules/taxonomy/taxonomy.module on line 70.

The node type in question are required to have terms selected from two vocabularies, "category" and "area", my version of Drupal is 6.14.

Does anyone knows why this happens?

Thanks.

dogbertdp’s picture

I'm having the issue and I'm not using the Bibliography module.

shawn_smiley’s picture

Version: 6.13 » 6.14

I'm also seeing the same error when previewing nodes. We don't have either the Bibliography or Taxonomy super select modules.

It only appears to happen on nodes that have more than one Vocabulary associated with them.

In my case, I have one content type that has 1 multiselect vocab associated with it that previews without error.

But another content type that has 2 multiselect vocabs associated with it generates the error in this issue.

In both cases, the vocabularies are configured as required. Toggling the required status does not seem to affect the error.

mennowas’s picture

I had the same problem and updated the filefield module. Ran update.php and the problem was gone.

shawn_smiley’s picture

This situation probably doesn't apply to anyone else, but here is what I found caused this error in our situation.

In our case, we have a module that converts the Taxonomy selection field from a multi-select select box to checkboxes on the node forms.

This part worked great, but the problem came when previewing since checkboxes show up slightly differently in the form_state than a multi-select list does.

Checkboxes will return an array of all checkboxes with the index being the term id and the value being either the term id (if checked) or 0 (if not checked). It's these 0 values that were causing the error.

Our solution was to add another submit handler to the form that massages the form_state to remove the 0 values from the taxonomy field before passing on to the default form handler.

Here is the code we used to massage the form_state:

function vsore_form_alter(&$form, $form_state, $form_id) {
 // Code to convert taxonomy select list to checkboxes omitted
  array_unshift($form['buttons']['preview']['#submit'], 'vsore_vs_ore_file_node_form_preview');
}

function vsore_vs_ore_file_node_form_preview(&$form, &$form_state) {
  foreach ($form_state['values']['taxonomy'] as $vid => $terms) {
    $form_state['values']['taxonomy'][$vid] = array_filter($terms);
  }
}

ressa’s picture

Version: 6.14 » 6.15

I too have 2 multi select vocabularies associated with the content type that generates the error, and also using the Hierarchical Select module, might this be the cause? http://drupal.org/project/hierarchical_select

Andrew Schulman’s picture

Version: 6.15 » 6.16

I'm also affected by this bug. I don't have Bibliography, Hierarchical select, or Taxonomy super select installed. I do run the Taxonomy access control lite (tac_lite) module.

I can't tell exactly what the user was doing when the errors occurred, but the referrer URL was node/add/page, so it was probably during a page preview, as was suggested earlier.

attiks’s picture

Ran into the same problem, changed line 69 to else if (!empty($term)) {

bricef’s picture

Version: 6.16 » 6.19

There still a bug. I think #17 is right and his solution will correct lot of bug.

sp_key’s picture

#17 works fine for me.
Thx!

Oiseau’s picture

I had the same warning when saving the node. But it was only in nodes which didn't use multipal select in taxonomy.
I added $term = (array)$term; before line 70
This solution works for me but I'm not sure if it's a good approach

jibize’s picture

I can confirm that the solution on #17 correct the warning I was having as well when trying to preview a node.
Thanks.

Sagar Ramgade’s picture

I tried solution on #17 it doesn't work for me, I am using just a taxonomy module for a content type with one select list and free tagging vocabulary. Can anyone help on this, logs full of these errors?

Sagar Ramgade’s picture

What if i combined both the solutions from comments #17 and #20 like :

<?php
else if (!empty($term)) {
$term = (array)$term;
foreach ($term as $free_typed) {
...

?>

Can anyone test this on test enviroment?

danjro’s picture

#17 appears to work for me, on Drupal 6.22:

diff modules/taxonomy/taxonomy.module.backup modules/taxonomy/taxonomy.module:

68c68
<         else {
---
>         else if (!empty($term)) {
ressa’s picture

#23 seems to work for me, on Drupal 6.20

k-boy’s picture

#23 seems to work for me, on Drupal 6.20

k-boy’s picture

#23 seems to work for me, on Drupal 6.20

dstol’s picture

Version: 6.19 » 6.x-dev
Status: Active » Needs review
FileSize
624 bytes

Here's a patch based on #23.

Sagar Ramgade’s picture

#28: invalid-arg-520490-28.patch queued for re-testing.

maddentim’s picture

patch applied to a site with the bug and it seems to have resolved the issue. Tempted to mark as rtbc but would prefer to see that more folks had success.

BrianLewisDesign’s picture

My "Invalid argument ... taxonomy.module" error was triggered by bad nodes.

They had language "en", even though there are no language modules installed.
I deleted them in Content Manager but they still showed up, though node page said content not available.
I removed the rows from the "node" table in the database -- solved.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.