You are here

function _group_context_handler_entity in Organic groups 7

Same name and namespace in other branches
  1. 7.2 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 549
Get a group from a viewed page.

Code

function _group_context_handler_entity($entity_type = 'node', $entity = NULL, $position = 1) {
  $context = array();
  if (empty($entity)) {
    $entity = menu_get_object($entity_type, $position);
  }
  if ($entity) {

    // Check if the entity is itself a group.
    list($id) = entity_extract_ids($entity_type, $entity);

    // Only proceed if it really is the entity and we got an id.
    if (isset($id)) {
      if ($group = og_get_group($entity_type, $id)) {
        $context = drupal_map_assoc(array(
          $group->gid,
        ));
      }
      elseif ($gids = og_get_entity_groups($entity_type, $entity)) {
        $context = $gids;
      }
    }
  }
  return $context;
}