Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It appears that you are unable to set the language property when running og_membership_type_create. The error returned is:
EntityMetadataWrapperException: Entity property language doesn't support writing. in EntityStructureWrapper->setProperty() (line 497 of /var/www/html/teams/sites/all/modules/entity/includes/entity.wrapper.inc).
Works fine if language is not set in the "values" array.
Comments
Comment #1
amitaibuBtw, Why not use og_group() ?
Comment #2
ejsteven CreditAttribution: ejsteven commentedHi Amitaibu.. Thanks for your reply. I am using og_group() but I'd like to programmatically create my own og membership types rather than just use the default one. Reason being that I'm going to attach some fields to my membership entity.
Comment #3
amitaibuAre you trying to create an OgMembership or OgMembershipType?
If it's OgMembership then use
og_membership_create()
, and the language is recognized by the wrapper -- seeOgMembershipMetadataController
Comment #4
ejsteven CreditAttribution: ejsteven commentedCurrently, I'm trying to create a OG Membership Type i.e. a new bundle by using og_membership_type_create(). In the current code, it is attempting to set the current system language to the OgMembershipType but fails. After I'm successful I will be using og_membership_create() or og_group() to establish memberships.
Comment #5
caxy4 CreditAttribution: caxy4 commentedI just ran into the same issue ejsteven did.
My workaround was to call
entity_property_values_create_entity('og_membership_type', $values)
with a custom$values
array and then save the value of the returned wrapper usingog_membership_type_save()
as follows.