You are here

function og_group_from_node_context in Organic groups 7

Return a new context based on an existing context.

1 string reference to 'og_group_from_node_context'
og_group_from_node.inc in plugins/relationships/og_group_from_node.inc
Plugin to provide an relationship handler for OG group from node.

File

plugins/relationships/og_group_from_node.inc, line 23
Plugin to provide an relationship handler for OG group from node.

Code

function og_group_from_node_context($context, $conf) {

  // If unset it wants a generic, unfilled context, which is just NULL.
  if (empty($context->data) || !isset($context->data->nid)) {
    return ctools_context_create_empty('entity:group', NULL);
  }
  $group = og_get_group('node', $context->data->nid);
  if (!$group) {

    // The node isn't a group, check if it's a group content.
    $node = clone $context->data;
    $gids = og_get_entity_groups('node', $node);
    if (!$gids) {
      return;
    }

    // Get the first group.
    $gid = reset($gids);
    $group = og_load($gid);
  }
  if (!$group) {
    return;
  }

  // Send it to ctools.
  return ctools_context_create('entity:group', $group);
}