You are here

function _group_context_handler_entity in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og_context/og_context.module \_group_context_handler_entity()

Helper function to get group context from an entity.

Parameters

$entity_type: The entity type.

$entity: Optional; The entity object.

$position: Optional; The position that should be used in menu_get_object().

3 calls to _group_context_handler_entity()
og_context_handler_node in og_context/og_context.module
Context handler; Get groups from existing node or ctools context.
og_context_handler_user_edit in og_context/og_context.module
Context handler; Get groups from user edit.
og_context_handler_user_view in og_context/og_context.module
Context handler; Get groups from user view.

File

og_context/og_context.module, line 632
Get a group from a viewed page.

Code

function _group_context_handler_entity($entity_type = 'node', $entity = NULL, $position = 1) {
  $contexts = array();
  if (empty($entity)) {
    $entity = menu_get_object($entity_type, $position);
  }
  if (!$entity) {
    return;
  }
  list($id) = entity_extract_ids($entity_type, $entity);
  if (!$id) {
    return;
  }

  // Check if the entity is itself a group.
  if (og_is_group($entity_type, $entity)) {
    $contexts[$entity_type][] = $id;
  }
  elseif ($gids = og_get_entity_groups($entity_type, $entity)) {
    $contexts = $gids;
  }
  return $contexts;
}