Getting a notice of an array to string error conversion on line 576 of the apachesolr_attachments.module.

As it turns out the $snippets variable is an array of arrays, and as such, the implode function throws the error. The snippets variable is in fact a keyed array with a 'content' key that then holds up to 3 integer indexed array keys that describe the file.

In order for me to get around this, I had to add the following line just above the return:

if(array_key_exists('content', $snippets)) $snippets = $snippets['content'];

Comments

posulliv’s picture

I also hit this issue. Attached is a patch with pretty much the fix mentioned in the original report.

Seems $snippets['content'] will always be set from looking at apachesolr_search_process_response in the apachesolr module.

David_Rothstein’s picture

Title: Array to String error » Array to String error when certain file attachments appear in the search results
Version: 7.x-1.2 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.63 KB

I don't think $snippets['content'] is always guaranteed to be there. The fact that it isn't is what causes issues like #1946132: ERROR: Warning: implode() [function.implode]: Invalid arguments passed in theme_apachesolr_search_snippets() (line 1708 of...) in the Apachesolr module itself.

Here's a patch for this issue that relies on the one I posted over there and therefore doesn't rely on $snippets['content'] being present. I'm not totally sure what to do about the @todo, though.

posulliv’s picture

That makes sense to me. Thanks for the pointer to the other issue; I wasn't aware of it.

Panther256’s picture

There is a typo in the return line of the patch. "return $vars['snippet']" should be "return $vars['snippets']":

+  return $vars['snippet'] . '<span>' . $file_type . ' <em>attached to:</em>' . implode(', ', $parent_entity_links) . '</span>';

Should be:

+  return $vars['snippets'] . '<span>' . $file_type . ' <em>attached to:</em>' . implode(', ', $parent_entity_links) . '</span>';

Otherwise, this does fix the issue for me.

Thanks!

David_Rothstein’s picture

It's not actually a typo; that variable is introduced in the other issue. (Leaving it at $vars['snippets'] would not fix the issue here.)

tim-e’s picture

StatusFileSize
new859 bytes

This worked for me.

Patch attached.

David_Rothstein’s picture

@tim-e, that looks like the same patch as #1?

Here is a reroll of #2 which tracks the latest patch from the other issue (#1946132-24: ERROR: Warning: implode() [function.implode]: Invalid arguments passed in theme_apachesolr_search_snippets() (line 1708 of...)). It's now using a different variable, but still the same approach.

jvandooren’s picture

Patch from #7 did not apply cleanly but I patched it manually and it fixed the issue...

Echofive’s picture

Hi,

I have been the same error and I've created a (correct :) patch based on the from #7 patch.
Enjoy it now !

David_Rothstein’s picture

#9 looks the same as #7 except there is an indentation problem in the code comments (see also https://drupal.org/coding-standards/docs#todo), so I think #7 is still the patch to review.

Functionally they should be the same though :)

nick_vh’s picture

Status: Needs review » Fixed

Looks great! Committing and giving credit to all of you but the commit will go to David.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.