I am seeing this message randomly on my pages. When I hit 'Refresh' it goes away.

Invalid argument supplied for foreach() in similarterms_taxonomy_node_get_terms()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

efarseer’s picture

I encoutered this bug also.

lelizondo’s picture

subscribing

migmedia’s picture

Is this a dup of #1260750: annoying bug The first argument should be an array?
If not please add the full error-message (with line-number etc.)

efarseer’s picture

Warning: Invalid argument supplied for foreach() in similarterms_taxonomy_node_get_terms() (line 517 in sites/all/modules/similarterms/similarterms.module).

funkeyrandy’s picture

no solutios here fix issue

nICEsCREAM’s picture

subscribing

Xen’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
1.29 KB

Patch fixes this warning and the one in #1260750: annoying bug The first argument should be an array.

funkeyrandy’s picture

AWESOME thanks!

pcambra’s picture

Status: Needs review » Reviewed & tested by the community

The patch fixes the warning, thanks!

cjs_’s picture

I applied this patch to 7.x-1.x-dev and am still getting the same error. Any thoughts? The module doesn't seem to be functioning as a result.

Evgenij’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta3

* Warning: Invalid argument supplied for foreach() in similarterms_taxonomy_node_get_terms_by_vocabulary() (line 536 of similarterms.module).
* Warning: array_keys() expects parameter 1 to be array, null given in similarterms_list() (line 196 of similarterms.module).

djmy’s picture

with patch getting it when i click on 'Similar entries from the Tags vocabulary.' block configuration
Warning: Invalid argument supplied for foreach() in similarterms_block_configure() (line 112 of /path/sites/all/modules/similarterms/similarterms.module).

areynolds’s picture

I inadvertently contributed to what is probably a duplicate of this issue:#1454412

I submitted a patch there against dev branch.

areynolds’s picture

The code seems to expect $item['taxonomy_term'] to be a fully populated term object of some sort. This doesn't seem to be the case; my debugging only showed $item['tid'].

Here's a fix against dev that resolves my issues. It could probably be more performant by matching the vocabulary machine name provided by $field with the vocabulary identified by $vid (right now it loads taxonomy terms). I'm wondering if I should...

  • Load the vocabulary object using taxonomy_vocabulary_load OR
  • Load the vocabulary machine name with db_query

Guessing a quick db_query is most performant, but maybe not as kosher, seeing as taxonomy_vocabulary_load() is an interface I can probably count on being around for a while.

tormu’s picture

I tested this patch against the dev version and seems to work.

John Pitcairn’s picture

I'm slightly confused what the status of this issue is now. Needs review?

aendra’s picture

Augh. I cannot get these warnings to disappear.

The patch in #7 fails with beta3.

The patch in #14 succeeds with 7.x.-1.x-dev but doesn't resolve the issue.

What am I doing wrong?

Currently using Drupal 7.14 and dev version of Similar By Terms.

mgifford’s picture

The patch above doesn't seem to be adding any checking in the foreach in similarterms_taxonomy_node_get_terms() to see if it is actually an array or not. I didn't look at it in any detail, but would be good to get this resolved.

lelizondo’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Reviewed & tested by the community » Needs review
FileSize
1.59 KB

Last patch didn't solve the problem for me.

Attaching a very simple patch that just adds a couple of "if".

The problem is only showing to me when there are no items to show on a block, so adding an if to only show if the module find terms solves it.

Please test against 7.x-1.x and report back

sourcesoft’s picture

Status: Needs review » Reviewed & tested by the community

All patches failed when #19 fixed the issue finally. Thank you!

mgifford’s picture

When applying this against the master branch in the git repo I get:

$ git apply similarterms-1277256-19.patch 
similarterms-1277256-19.patch:20: trailing whitespace.
      } 
error: patch failed: similarterms.module:190
error: similarterms.module: patch does not apply
lelizondo’s picture

use patch -p0 (or p1)

mgifford’s picture

It really depends on how the maintainer wants to deal with it. A patch applied with git is often easier to bring in.

This issue should really get brought into the repo and set up for the next release before it's a year old. It's a simple enough check and an annoying enough error.

takim’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Closed (outdated)

7.x-1.x is not anymore supported and maintained. Please use 7.x-2.x version for your websites.