After upgrading to 2.4 I get the following errors on node save:

Notice: Undefined index: #entity in og_form_group_reference_validate() (line 754 of xxx/sites/all/modules/contrib/og/og.module).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7697 of xxx/includes/common.inc).

I could not reproduce it on a clean install but I will try. In the meantime, I'm attaching a patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

czigor’s picture

Status: Active » Needs review
FileSize
519 bytes
czigor’s picture

I succeeded to reproduce the error.

1. Install a minimal Drupal.
2. Enable og_ui (with all its dependencies) and field_ui.
3. Create a content type "Group" and select "Group" on the "Organic Group" tab on the content type edit page.
4. Add a Group node.
5. Create a content type "Page" and select "Group content" on the "Organic Group" tab on the content type edit page. Select 'Group' as bundle.
6. Remove the body field from Page so that the only remaining field is og_group_ref. The cardinality and requiredness of og_group_ref does not seem to matter.
6a. EDIT: Change the og_group_ref widget from OG Reference to Select.
7. Try to create a page by submitting the node/add/page form.

You should see a white error page with the following text:

Notice: Undefined index: field_mode in OgBehaviorHandler->validate() (line 246 of xxx/sites/all/modules/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php).
Notice: Undefined index: #entity in og_form_group_reference_validate() (line 754 of xxx/sites/all/modules/og/og.module).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7697 of xxx/includes/common.inc).

The problem comes from the core field_default_form() which creates $form['#entity'] only

  if (!isset($get_delta) && field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT)

However, $form['#node'] is always added by node_form().

EDIT: I left out one thing: The widget of the og_group_ref field must be 'Select', not the default OG Reference. It is not clear yet, whether selects should be allowed at all for og_group_ref fields. See #2141101: Plain core select widget does not work for og_group_ref fields.

bjcooper’s picture

I've run into the same error. I can reproduce the problem as described and confirm that the patch fixes it (at least in my case).

Still keeping an eye on the other thread to see if using the 'select list' widgit will be allowed.

bjcooper’s picture

Also, I should mention that I got this when adding the Group Audience field to the core Polls node type, since it has no Body field.

jraviotta’s picture

I experienced this error also. Patch in #1 solved the error

shushu’s picture

Status: Needs review » Closed (duplicate)
shushu’s picture

czigor’s picture

Status: Closed (duplicate) » Needs review

Why is this a duplicate? This is a different issue with a different patch.

shushu’s picture

Status: Needs review » Postponed (maintainer needs more info)

As far as I can tell this issue happen since using the select widget instead of the OG widget.
If this issue still exist after solving #2141101: Plain core select widget does not work for og_group_ref fields then you are correct, and this should be handled separately.
Can you verify it still exist ?

czigor’s picture

Status: Postponed (maintainer needs more info) » Needs review

Yes, it does exist. It is related to #2141101: Plain core select widget does not work for og_group_ref fields since it only happens when using the select widget but it is a different issue. Do the steps to reproduce in #2 not work for you?

shushu’s picture

Status: Needs review » Needs work

True, once removing the body field and using the select box widget, I was able to reproduce the problem and the patch solved it.
But then I tried to reproduce the scenario with non-node group content (using taxonomy term), and I wasn't able to reproduce either with and without the patch.
Debugging it, I think there is a problem in og_form_group_reference_validate() when it is doing:

if (empty($form_state[$entity_type])) {
    // We are inside field settings page.
    return;
  }

I know it is not 100% related to the issue, but I won't want to push a fix in og_form_group_reference_validate() without being able to actually use it with non-node entities.
I will continue to investigate this.

czigor’s picture

I think you're right. There are two problems in og_form_group_reference_validate():

  1. $form_state[$entity_type] is not necessarily set and therefore it thinks "We are inside field settings page". (For example in the case of taxonomy_terms instead of $form_state['taxonomy_term'] $form_state['term'] is set.) We need a different logic here to determine where we are.
  2. Even if it did not think that we are inside a field settings page $form['#entity'] is not necessarily set. Whether it is set or not is decided in field_default_form(). We should check first if $form['#entity'] is set and if not, we should try and get $entity from $form['og_group_ref'][LANGUAGE_NONE][0]['#entity'] (or whatever $field_name og_get_group_audience_fields() is returning.)

What do you think?

czigor’s picture

Title: EntityMalformedException on 2.4 » EntityMalformedException with select og_audience widget if group content has no other fields
FileSize
1.21 KB

The patch does the following:

  1. og_form_group_reference_validate() does not get called when submitting a field settings page. My guess is that 2 years ago when the 4 lines in #11 got commited it did get called but the validation has got refactored into OgBegaviorHandler::validate() since. So the patch removes these 4 lines.
  2. It tries to get the entity from $form['#entity'] and if it fails it gets it from the og_audience field form element's #entity property as that's where it should be according to field_default_form().
czigor’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: og-entity_key-2143733-13.patch, failed testing.

czigor’s picture

Status: Needs work » Needs review

13: og-entity_key-2143733-13.patch queued for re-testing.

shushu’s picture

Do you have a scenario to use in order to reproduce situation #2 - entity inside og_audience field form element ?

czigor’s picture

Yes, it is the scenario described in comment #2. If (as most often is the case) $form['#entity'] is set this issue does not appear.

shushu’s picture

Status: Needs review » Reviewed & tested by the community
John Carbone’s picture

Thanks guys! I was seeing errors with og_form_group_reference_validate() throwing undefined index warnings when saving users and this patch cleared it up. I couldn't find a more specific issue so I'm including the errors I was getting in case anyone else finds this thread.

The errors:
Notice: Undefined index: #entity in og_form_group_reference_validate() (line 737 of sites/all/modules/contrib/og/og.module).
Notice: Undefined index: field_mode in OgBehaviorHandler->validate() (line 254 of sites/all/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php).

dobe’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
998 bytes

Unfortunately, this patch needs reviewed again. Patch #13 removes the check to see if empty($form_state[$entity_type]). This causes an issue when dealing with single field forms (The FAPE module). This causes problems on fields that are not OG. Where the entity type being passed comes up null and throws:
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids()

-Jesse

Jeff Veit’s picture

Patch in #21 works for me.

I'm encountering the error because I'm using the Field Permissions module, and some users do not have the rights to see or edit the list of groups.

maikeru’s picture

Status: Needs review » Reviewed & tested by the community

#21 also works for me when using checkboxes, when previously I was getting the error reported by OP

Angry Dan’s picture

FileSize
527 bytes

Isn't it easier to just define #entity in og_field_attach_form()?

This fixed the issue for me, and seems easier than grepping around the built form.

drupal3013’s picture

The patch on comment Number 24
worked for me

dtarc’s picture

We're also using the patch in #24 successfully.

hbensalem’s picture

+1 to patch #24 works great for us

amitaibu’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks.

  • amitaibu committed 841cc25 on 7.x-2.x authored by Angry Dan
    Issue #2143733 by czigor, Angry Dan, dobe: EntityMalformedException with...

Status: Fixed » Closed (fixed)

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