Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#28 | invalid-arg-520490-28.patch | 624 bytes | dstol |
Comments
Comment #1
qpal CreditAttribution: qpal commentedI am having the exact same problem here.
Comment #2
aasarava CreditAttribution: aasarava commentedIf 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
Comment #3
portulacaI'm not using Taxonomy super select, I do have Taxonomy image, I'll test to see if it makes a difference.
Comment #4
lewisheadden CreditAttribution: lewisheadden commentedThis 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
Comment #5
el7cosmosThe 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.
Comment #6
Lanae CreditAttribution: Lanae commentedI 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.
Comment #7
skizzo CreditAttribution: skizzo commentedI 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.
Comment #8
dogbertdp CreditAttribution: dogbertdp commentedI'm also experiencing this issue. Has anyone tried the suggestion in #4? Is it a good approach?
Thanks,
Mike Hays
Comment #9
Lanae CreditAttribution: Lanae commentedThe 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.
Comment #10
ressa CreditAttribution: ressa commentedThe 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.
Comment #11
dogbertdp CreditAttribution: dogbertdp commentedI'm having the issue and I'm not using the Bibliography module.
Comment #12
shawn_smiley CreditAttribution: shawn_smiley commentedI'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.
Comment #13
mennowas CreditAttribution: mennowas commentedI had the same problem and updated the filefield module. Ran update.php and the problem was gone.
Comment #14
shawn_smiley CreditAttribution: shawn_smiley commentedThis 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:
Comment #15
ressa CreditAttribution: ressa commentedI 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
Comment #16
Andrew Schulman CreditAttribution: Andrew Schulman commentedI'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.
Comment #17
attiks CreditAttribution: attiks commentedRan into the same problem, changed line 69 to
else if (!empty($term)) {
Comment #18
bricef CreditAttribution: bricef commentedThere still a bug. I think #17 is right and his solution will correct lot of bug.
Comment #19
sp_key CreditAttribution: sp_key commented#17 works fine for me.
Thx!
Comment #20
Oiseau CreditAttribution: Oiseau commentedI 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 70This solution works for me but I'm not sure if it's a good approach
Comment #21
jibize CreditAttribution: jibize commentedI can confirm that the solution on #17 correct the warning I was having as well when trying to preview a node.
Thanks.
Comment #22
Sagar Ramgade CreditAttribution: Sagar Ramgade commentedI 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?
Comment #23
Sagar Ramgade CreditAttribution: Sagar Ramgade commentedWhat if i combined both the solutions from comments #17 and #20 like :
Can anyone test this on test enviroment?
Comment #24
danjro CreditAttribution: danjro commented#17 appears to work for me, on Drupal 6.22:
diff modules/taxonomy/taxonomy.module.backup modules/taxonomy/taxonomy.module:
Comment #25
ressa CreditAttribution: ressa commented#23 seems to work for me, on Drupal 6.20
Comment #26
k-boy CreditAttribution: k-boy commented#23 seems to work for me, on Drupal 6.20
Comment #27
k-boy CreditAttribution: k-boy commented#23 seems to work for me, on Drupal 6.20
Comment #28
dstolHere's a patch based on #23.
Comment #29
Sagar Ramgade CreditAttribution: Sagar Ramgade commented#28: invalid-arg-520490-28.patch queued for re-testing.
Comment #30
maddentim CreditAttribution: maddentim commentedpatch 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.
Comment #31
BrianLewisDesign CreditAttribution: BrianLewisDesign commentedMy "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.