When setting criteria for custom voting, getting an error message as array is not set:

Warning: Invalid argument supplied for foreach() in votingapi_votingapi_storage_select_votes() (line 214 of ../votingapi/votingapi.module).

CommentFileSizeAuthor
#2 criteria_warning-2375085-1.patch866 bytesfmitchell

Comments

fmitchell’s picture

Issue summary: View changes
fmitchell’s picture

Status: Active » Needs review
StatusFileSize
new866 bytes

Attaching patch.

tr’s picture

Version: 7.x-2.12 » 7.x-2.x-dev

Patch still applies. Reviews please ...

tr’s picture

Status: Needs review » Closed (works as designed)

OK, I finally got around to looking at this ...

votingapi_votingapi_storage_select_votes() is an implementation of hook_votingapi_storage_select_votes(). This hook is ONLY called by votingapi_select_votes() - no other code should be invoking hook functions directly.

I have checked, and votingapi_select_votes() will ALWAYS pass an array as the first parameter to hook_votingapi_storage_select_votes(). It will NEVER pass a null or a non-array value. The hook itself is documented to take an array as the first argument, but because of Drupal's architecture there is no way to enforce that, except for the fact that the only place the hook should be called is from within the module that defines the hook. Voting API calls its own hooks correctly.

In short, there is no way that this error should ever happen unless you are calling votingapi_votingapi_storage_select_votes() directly from your code. And if you are doing that, you should NOT be doing that. And if you really want to do that anyway, it's the responsibility of YOUR code to ensure that it is called correctly.