function og_context_determine_context in Organic groups 7
Same name and namespace in other branches
- 7.2 og_context/og_context.module \og_context_determine_context()
Determine the best matching context of a viewed page.
Parameters
$item: Optional; A menu item that context should be extracted from. If empty defaults to the current menu item by using menu_get_item().
1 call to og_context_determine_context()
- og_context in og_context/
og_context.module - Get or set group context using the menu system.
File
- og_context/
og_context.module, line 430 - Get a group from a viewed page.
Code
function og_context_determine_context($item = NULL) {
$context = FALSE;
// Enable url and node context handlers by default.
$defaults = array(
'url' => -5,
'node' => -4,
);
if ($enabled_providers = array_keys(variable_get("og_context_negotiation_group_context", $defaults))) {
if (empty($item)) {
$item = menu_get_item();
}
foreach (og_context_negotiation_info() as $name => $provider) {
if (in_array($name, $enabled_providers)) {
$invoke = FALSE;
if (!empty($provider['menu path'])) {
foreach ($provider['menu path'] as $path) {
if (strpos($item['path'], $path) === 0) {
$invoke = TRUE;
// Path matches, so we can break.
break;
}
}
}
else {
// Context isn't determined by the menu item.
$invoke = TRUE;
}
$gids = array();
if ($invoke && ($gids = call_user_func($provider['callback']))) {
// Check if one of the group IDs already exists in the session, and if
// so use it.
if (!empty($_SESSION['og_context']) && in_array($_SESSION['og_context'], $gids)) {
$gid = $_SESSION['og_context'];
}
else {
// Grab the first group ID.
$gid = reset($gids);
}
$context = og_load($gid);
// We found the first context, so we can break.
break;
}
}
}
}
return $context;
}