Hello,

I am using the latest files from 7.x-dev and it appears that because of a sudden change in the files (i couldn't find any specific one) i've started to recieve warnings in my front page which is default node listing of drupal.

The error message is;

Warning: Invalid argument supplied for foreach() in taxonomy_field_formatter_prepare_view() (line 1429 of /home/...../drupal/modules/taxonomy/taxonomy.module).

This error is repeated n times where n is the number of nodes to be listed in the default node listing.

My solution is;

File: taxonomy.module
Line: 1429
Change:

    foreach ($items[$id] as $delta => $item) {
      // Force the array key to prevent duplicates.
      if ($item['tid'] != 'autocreate') {
        $tids[$item['tid']] = $item['tid'];
      }
    }

to:

      if(!empty($items[$id]))
      {
        foreach ($items[$id] as $delta => $item) {
          // Force the array key to prevent duplicates.
          if ($item['tid'] != 'autocreate') {
            $tids[$item['tid']] = $item['tid'];
          }
        }
      }

I believe the error is because of empty arrays.

Waiting feedback and comment on this.

Thanks

Comments

hljhljhlj’s picture

I have the same bug,i use drupal 7.2

hljhljhlj’s picture

my web is http://guanyuexiaozhu.com,I dsiable local module and it is ok.

erdembey’s picture

Did you try my solution ?

hljhljhlj’s picture

I try it.Now it is ok now.I think it is a bug.

rodrigoaguilera’s picture

have the same bug on drupal 7.2 disabling locale makes the error disapear but i need locale.

fietserwin’s picture

Same for me, since my update to 7.2. I could trace back the change to issue #1089174: Prepare view hooks do not receive the language parameter and commit http://drupalcode.org/project/drupal.git/commit/2a419f61aafc5ad490eef0be....

A seemingly related issue is reported in #1169426: Field invoke multiple does not handle field language correctly. So is this a duplicate of that one?

Even after a long debug session i'm not sure about the solution. Should the calling function pass in an empty array instead of NULL in the $items array, or should taxonomy (and other modules implementing the hook) expect to receive NULL's in the $items array?

fietserwin’s picture

Status: Active » Closed (duplicate)

Patch in #7 of #1169426: Field invoke multiple does not handle field language correctly (http://drupal.org/node/1169426#comment-4527448) solves this problem for me. So marking this one as a duplicate.

darq88’s picture

eee...how to install this patch? :D

kifuzzy’s picture

a second (same) message comes with yours above:

" ..... on line 1446 ..."

your way to check if its empty solve my prob with drupal 7.2 german language
and the first message with the line 1429, i put the code to tax..module and i use
it for the "for each" on line 1446.

thx for this!

alienzed’s picture

I still see this error all the time, now in Drupal 7.51, how is this not resolved yet?