You are here

function og_context_handler_node in Organic groups 7

Same name and namespace in other branches
  1. 7.2 og_context/og_context.module \og_context_handler_node()

Context handler; Get groups from existing node or ctools context.

1 string reference to 'og_context_handler_node'
og_context_og_context_negotiation_info in og_context/og_context.module
Implements hook_og_context_negotiation_info().

File

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

Code

function og_context_handler_node() {
  $node = menu_get_object('node');
  if ($node) {
    return _group_context_handler_entity('node', $node);
  }

  // The path may not be %node, but in fact is a ctools-context, so extract the
  // node from it. We check only the 1st position (e.g. node/%/foo).
  $item = menu_get_item();
  if (empty($item['map'][1]) || !is_object($item['map'][1]) || !$item['map'][1] instanceof ctools_context) {
    return;
  }

  // Check the context is a node type. We check only path similar to node/%/foo
  // and don't traverse over the whole arguments, as it might be a page manager
  // page passing multiple nodes (e.g. some/path/with/%node/%node). Implementing
  // modules wanting to handle the above example, should implement their own
  // context handler.
  $context = clone $item['map'][1];
  if (empty($context->type[0]) || $context->type[0] != 'entity:node') {
    return;
  }
  return _group_context_handler_entity('node', $context->data);
}