function og_get_group in Organic groups 7
Return a loaded group entity if exists or create a new one.
This is a wrapper function around og_load() that allows passing the group's entity type and entity ID, and the correct group will be loaded accordingly. If no group exists and $create option is set to TRUE, then a new group entity will be created.
Parameters
$etid: The group content ID.
$entity_type: The group entity type. "node" is the default value. Pass "group" if content ID is equal to the group unique ID.
$create: Optional; If no existing group is found, create a new one. Defaults to FALSE.
$states: Array of states the group must be in. Values can be OG_STATE_ACTIVE, OG_STATE_PENDING or OG_STATE_BLOCKED. Defaults to OG_STATE_ACTIVE.
$reset: A boolean indicating that the internal cache should be reset.
Return value
The group entity if found, or an empty array.
58 calls to og_get_group()
- generate-og-d7-content-update-7001.php in scripts/
generate-og-d7-content-update-7001.php - OgAccessTestCase::testOgAccess in og_access/
og_access.test - Group with access field .
- OgAccessTestCase::testOgContentAccessDefault in og_access/
og_access.test - Group with access field and group content with default definition.
- OgAccessTestCase::testOgContentAccessNotDefault in og_access/
og_access.test - Group with access field and group content with different definition from the group.
- OgAccessTestCase::testOgStrictPrivate in og_access/
og_access.test - Test "Strict private" variable enabled or disabled.
File
- ./
og.module, line 1236 - Enable users to create and manage groups with roles and permissions.
Code
function og_get_group($entity_type, $etid, $create = FALSE, $states = array(
OG_STATE_ACTIVE,
), $reset = FALSE) {
$group = FALSE;
if ($gids = og_get_group_ids($entity_type, array(
$etid,
), $states, $reset)) {
// We don't use the entity ID directly, as it might change. For example, if
// a node is a translation of another node that is a group, we need to load
// the other node. og_get_group_ids() returns the correct entity ID as the
// key, so we will use that.
$correct_etid = key($gids);
$group = og_load($gids[$correct_etid], $reset);
}
elseif ($create) {
$group = og_create_group(array(
'entity_type' => $entity_type,
'etid' => $etid,
));
}
return $group;
}