After upgrading 7.x-2.0-rc1 from beta4 I get the message :

Warning: Invalid argument supplied for foreach() in og_field_widget_form() (line 69 of /var/www/maket/sites/all/modules/og/includes/

when creating group content using Entity reference prepopulate module and enabled "Prepopulate" in the field settings.
Creation is OK with or without select group in URL.

#17 1876696_ogfield_warning_erp_17.patch612 bytesjrbeeman
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es). View


amitaibu’s picture

Is this happening to you also on a clean installation of OG?

kaw3939’s picture

It is also happening to me on a clean install exactly as described.

mvlabat’s picture

Have the same issue. But I only today installed Entity reference prepopulate module (OG had been updated yesterday).

sodapopbob’s picture

I am only getting the error when I have the "Entity reference prepopulate" check box checked. Unchecked is fine.

PlayfulWolf’s picture

can confirm the same on rc1

JvE’s picture

This looks like a duplicate of #1825256: Does not work for Organic groups og_group_ref field

entityreference_prepopulate messes up in entityreference_prepopulate_og_field_default_value() by returning NULL rather than an array when the $instance has no 'field_mode'.

No idea why the upgrade from beta4 to rc1 caused field instances to have no field_mode
The other ticket also sheds no light in why that check of field_mode is done.

Edit: I think og_update_7203 has something to do with the problem.

amitaibu’s picture

I can't reproduce with the most up-to-date -dev version -- have you tried it?

PlayfulWolf’s picture

no, I am using rc1.
Is it safe to upgrade?

edited: sorry, stupid question - will try on dev copy and report

PlayfulWolf’s picture

Version: 7.x-2.0-rc1 » 7.x-2.x-dev
Status: Active » Needs review

Warning disappeared for me, using 2013 01 03 dev, everything else seems normal

ishiomin’s picture

Status: Needs review » Closed (fixed)

Yes It's OK now for me to.

Thank you

flashwebcenter’s picture

This warning happened when I updated og to 7.2 rc1
Warning: Invalid argument supplied for foreach() in og_field_widget_form() (line 69
I used the the dev version (2013-Jan-03) and this warning was gone. Thank you for the help.

LeviThomason’s picture

Confirming same issue and resolution. Warning message appeared after upgrading to 7.x-2.0-rc1 from beta4. Message disappeared after upgrading to dev 7.x-2.0-rc1+9-dev (2013-Jan-03).


JvE’s picture

Status: Closed (fixed) » Needs work

for the record, I disagree with the "fix" in the dev release:

 function og_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  if (!empty($items)) {
    foreach ($items as $item) {
      $entity_gids[] = $item['target_id'];

According to the API hook_field_widget_form() $items should always be an array, either filled or empty. Both cause no problem in foreach, making the check for empty() redundant.
Any function that causes $items to be NULL (or anything other than an arry) is at fault and should be fixed.
In this case it is entityreference_prepopulate which has multiple code paths that return NULL in stead of an array when providing $items. @see #1825256: Does not work for Organic groups og_group_ref field

royerd’s picture

Same issue here, but using the DEV version does not fix it in my case. I see, i should have updated the ER prepopulate module--I did and that fixed it.

amitaibu’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

jrbeeman’s picture

Status: Closed (fixed) » Needs review
612 bytes
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es). View

Re-opening because we ran into this issue in the Commons sprint, even with the updated version of entityreference_prepopulate. The error occurs when you go to add a post without a group reference in the URL string. I think the fix is simple: don't assume we've got items. Patch against 7.x-2.x attached.

JvE’s picture

Status: Needs review » Closed (works as designed)

@jrbeeman: please read comment #13
Your patch is identical to the previous "fix" and does not fix the issue, it merely hides the fact that another module is breaking the API.
You may want to re-open #1825256: Does not work for Organic groups og_group_ref field because the behaviour you describe was fixed there.