diff --git a/og_context/og_context.module b/og_context/og_context.module index edacfe7..5ed2735 100644 --- a/og_context/og_context.module +++ b/og_context/og_context.module @@ -138,6 +138,13 @@ function og_context_og_context_negotiation_info() { 'menu path' => array('user/%/edit'), ); + $providers['comment'] = array( + 'name' => t('Comment'), + 'description' => t("Determine context by checking if the parent content of the comment belongs to a group"), + 'callback' => 'og_context_handler_add_comment', + 'menu path' => array('comment/reply/%', 'comment/%'), + ); + return $providers; } @@ -405,8 +412,12 @@ function og_context_handler_url() { /** * Context handler; Get groups from existing node or ctools context. */ -function og_context_handler_node() { - if ($node = menu_get_object('node')) { +function og_context_handler_node($node = NULL) { + + if (!is_null($node)) { + return _group_context_handler_entity('node', $node); + } + elseif ($node = menu_get_object('node')) { return _group_context_handler_entity('node', $node); } @@ -457,6 +468,20 @@ function og_context_handler_user_edit() { } /** + * Context handler; Get groups from parent of comment being added to it. + */ +function og_context_handler_add_comment() { + $comment_path = menu_get_item(); + $comment = comment_load(end($comment_path['original_map'])); + if (isset($comment->nid)) { + return og_context_handler_node(node_load($comment->nid)); + } + else { + return; + } +} + +/** * Helper function to get group context from an entity. * * @param $entity_type