Community Documentation

Developing on OG 7.x-2.x

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:

  • How to obtain a list of members for a given group entity.

--
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

Page status

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Level
Advanced
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.