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/og.field.inc).

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.

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

Comments

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

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

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

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

can confirm the same on rc1

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.

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

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

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

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

Status:Needs review» Closed (fixed)

Yes It's OK now for me to.

Thank you

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.

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).

Thanks!

Status:Closed (fixed)» Needs work

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

<?php
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

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.

Status:Needs work» Fixed

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Needs review
StatusFileSize
new612 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.

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.