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.
TODO: overview of entity types, field types, and how they all glue together.
Working with groups and group content
Given an entity that is group content:
$wrapper = entity_metadata_wrapper(ENTITY_TYPE, $entity);
$og_membership_entity = $wrapper->og_group_ref->value();
Comments
Some TODOs
Something that would be useful to know:
--
Damien McKenna | Mediacurrent
@DamienMcKenna How to obtain
@DamienMcKenna
Have you figured out how to do this? After 1 hour of research it looks like we have to write a custom SQL statement just to grab a list of group members. I have a hard time believing this as I thought there would be an existing function like og_get_members($gid);
Here's the Drupal 7 solution
Here's the Drupal 7 solution to programmatically obtain the names of group members after specifying a Group ID:
This is much faster (at least 3x faster) than using a Drupal function including EntityFieldQuery();
A small helper function to
A small helper function to load all of the group nodes that the user is a member of:
--
Damien McKenna | Mediacurrent