I have both Organic Groups (og) and Bean enabled on a test site. I would like to be able to assign bean blocks to groups. I am able to add the Groups Audience field (provided by og) to my block type. However, if I create or edit a block and try to set the Groups Audience field, I get the following error:

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 744 of .../sites/all/modules/contrib/entity/includes/entity.wrapper.inc).

If I leave the groups audience field set to "none", I am able to save the block.

Files: 
CommentFileSizeAuthor
#4 og-use_numeric_id_for_membership_etid-1880226-4.patch2.31 KBcecrs
PASSED: [[SimpleTest]]: [MySQL] 894 pass(es).
[ View ]
#3 og-use_numeric_id_for_membership_etid-1880226-3.patch2.22 KBacrollet
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]
#2 og-use_numeric_id_for_membership_etid-1880226-2.patch1.45 KBacrollet
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

Comments

Status:Active» Postponed (maintainer needs more info)

Hey Paul,

The latest release contains some fixes to the Entity Metadata which might fix some of these issues. Can you please test?

Title:Cannot set organic groups Groups Audience field in a bean blockCannot set organic groups Groups Audience field on an entity with a "name" key
Project:Bean» Organic groups
Version:7.x-1.0-rc7» 7.x-2.x-dev
Component:Code» og.module
Status:Postponed (maintainer needs more info)» Needs review
StatusFileSize
new1.45 KB
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

I had this problem, as described by OP. What I found is that the audience field assumes that it will get a numeric identifier. (See the schema for the etid column on the og_membership table). However, EntityMetadataWrapper's getIdentifier method returns the field specified by the 'name' entity key, if present. I modified the og code to always get the id, as opposed to the machine name. Patch attached, although it's probably more a starting point for discussion than a committable patch, given that getIdentifier() is used in several other places. That being said, this patch does allow one to save a new bean entity with an attached group audience field, and did not affect the ability to save a new node with a group audience field.

StatusFileSize
new2.22 KB
PASSED: [[SimpleTest]]: [MySQL] 780 pass(es).
[ View ]

updated patch attached - this also modifies the load method of the OgBehaviorHandler class, allowing the selected audience to be seen when viewing a bean.

StatusFileSize
new2.31 KB
PASSED: [[SimpleTest]]: [MySQL] 894 pass(es).
[ View ]

Re-rolled against the latest dev.