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.

Support from Acquia helps fund testing for Drupal Acquia logo

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 (for Drupal 7) » 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
FileSize
1.45 KB

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

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

Re-rolled against the latest dev.

Chris Burge’s picture

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.

jaarong’s picture

#5 appears to have worked for me as well.

HLopes’s picture

Same issue here, #5 fixed it.

Chris Burge’s picture

Status: Needs review » Reviewed & tested by the community