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
#5 og-use_numeric_id_for_membership_etid-1880226-5.patch1.7 KBChris Burge
PASSED: [[SimpleTest]]: [MySQL] 1,165 pass(es).
[ View ]
#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

indytechcook’s picture

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?

acrollet’s picture

Title:Cannot set organic groups Groups Audience field in a bean block» Cannot 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.

acrollet’s picture

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.

cecrs’s picture

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

Re-rolled against the latest dev.

Chris Burge’s picture

Issue summary:View changes
StatusFileSize
new1.7 KB
PASSED: [[SimpleTest]]: [MySQL] 1,165 pass(es).
[ View ]

Re-rolled patch against the latest dev.

The 'includes/og.membership.inc' file has been reworked since the last patch was posted on this issue, and its respective hunk no longer applies. This hunk has been removed from this patch. The code in question was modified by #2231217: Prevent loading entity in \OgMembership::save() upon og_group(), which also employs the 'entity_load_single' function.

My testing indicates the patch continues to work as designed.

FrancescoQ’s picture

Hi, i've tried #5 and works for me. Now i'm testing, I tell you if something goes wrong! Thanks.