Last updated January 9, 2013. Created by joachim on January 9, 2013.
Log in to edit this page.
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
A small helper function to
A small helper function to load all of the group nodes that the user is a member of:
<?php
/**
* Provide an array of groups the member is in.
*
* @param $uid integer
* The user's uid.
*
* @return array
* An array of the full group objects, presumably nodes.
*/
function example_load_user_groups($uid) {
// Load the user.
$account = user_load($uid);
// Build a list of the groups.
$groups = array();
if (!empty($account->og_user_node[LANGUAGE_NONE][0]['target_id'])) {
// Load each group object. Note: this assumes the objects are nodes.
// TODO: Clear the entitycache object when the nodes are modified.
foreach ($account->og_user_node[LANGUAGE_NONE] as $gref) {
if (!empty($gref['target_id']) && is_numeric($gref['target_id'])) {
$groups[$gref['target_id']] = node_load($gref['target_id']);
}
}
}
return $groups;
}
?>
--
Damien McKenna | Mediacurrent