Skip to content

Instantly share code, notes, and snippets.

@skwashd
Created July 7, 2013 14:14
Show Gist options
  • Save skwashd/5943593 to your computer and use it in GitHub Desktop.
Save skwashd/5943593 to your computer and use it in GitHub Desktop.
Extract a list of all Organic Groups groups with their names. Works with OG 7.x-2.x - tested with 7.x-2.2.
<?php
/**
* Extract a list of all available Organic Groups.
*
* This is ugly and inefficient, but it is the only way
* I could figure out how to do it, but hey it works.
*
* This is designed to work with OG 7.x-2.x
*
* @params array $entity_types
* Limit the search to the entity types specified. All types checked if omitted.
*
* @return array
* All of the groups in the site.
*/
function mymodule_get_all_groups($entity_types = NULL) {
if (NULL === $entity_types) {
$entity_types = array_keys(og_get_all_group_entity());
}
$groups = array();
foreach ($entity_types as $entity_type) {
foreach (entity_load($entity_type, og_get_all_group($entity_type)) as $id => $entity) {
$groups["{$entity_type}__{$id}"] = entity_label($entity_type, $entity);
}
}
return $groups;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment