diff --git a/og_menu.module b/og_menu.module index 5de9862..4aa01dd 100644 --- a/og_menu.module +++ b/og_menu.module @@ -468,6 +468,12 @@ function og_menu_node_prepare($node) { // $node is a group type. if (og_is_group_type('node', $node->type)) { $node->og_menu = og_menu_get_menus(); + if (!empty($node->nid)) { + $og = og_get_group('node', $node->nid, FALSE, array(OG_STATE_ACTIVE, OG_STATE_PENDING)); + if (isset($og->gid)) { + $node->og_menu = og_menu_get_menus(array($og->gid)); + } + } } // $node is not a new node and is a group content type, menu link is not set. // @todo This used to exclude users with user_access('administer menu'), test the consequences of this change. @@ -636,8 +642,9 @@ function og_menu_get_menus($gids = NULL, $user = NULL) { } if (!$gids) { $nodegroups = og_load_multiple(og_get_entity_groups('user', $user)); - foreach ($nodegroups as $ng) + foreach ($nodegroups as $ng) { $gids[] = $ng->gid; + } } $menus = array(); if ($gids) { @@ -655,7 +662,6 @@ function og_menu_get_menus($gids = NULL, $user = NULL) { $menus[] = $menu; } } - return $menus; } diff --git a/og_menu_pane/og_menu_pane.info b/og_menu_pane/og_menu_pane.info new file mode 100644 index 0000000..59b76e3 --- /dev/null +++ b/og_menu_pane/og_menu_pane.info @@ -0,0 +1,9 @@ +name = OG Menu Panes +description = Allows OG Menus to be used in Panels. +dependencies[] = og_menu +dependencies[] = ctools +dependencies[] = panels +dependencies[] = menu_block +core = 7.x +package = Organic groups +files[] = og_menu_pane.module diff --git a/og_menu_pane/og_menu_pane.module b/og_menu_pane/og_menu_pane.module new file mode 100644 index 0000000..f2e1a90 --- /dev/null +++ b/og_menu_pane/og_menu_pane.module @@ -0,0 +1,15 @@ + t('OG Menu pane'), + 'description' => t('This pane renders a OG Menu'), + 'single' => TRUE, // 'single' => TRUE means has no subtypes. + 'content_types' => array('og_menu_pane_content_type'), // Constructor. + // Name of a function which will render the block. + 'render callback' => 'og_menu_pane_content_type_render', + 'edit form' => 'og_menu_pane_content_type_edit_form', + // Add our content type to Organic Groups category. + 'category' => array(t('Organic Groups'), -9), + 'required context' => new ctools_context_required(t('Organic groups membership: Group gid'), 'group'), + 'context' => 'og_group_from_node_context', +); + +/** + * Renders a og_menu content type based on context supplied in configuration. + * + * @param $subtype + * @param $conf + * Configuration as done at admin time. + * @param $args + * @param $context + * Context; in this case we mean the OG. + * + * @return + * object An object with at least title and content members. + */ +function og_menu_pane_content_type_render($subtype, $conf, $args, $context) { + // We require a context for this pane to render. + if (empty($context->data)) { + return FALSE; + } + // Get the gid from group that is available in the context. + $gid = $context->data->gid; + // Get the OG menu for the group. + $menus = og_menu_get_menus(array($gid)); + $menu = array_shift($menus); + + if ($menu) { + $block = new stdClass(); + $block->title = check_plain($menu->mtitle); + // Link the pane title to the group if this has been set in configuration. + if (isset($conf['og_menu_pane_block_links']) && $conf['og_menu_pane_block_links']) { + $block->title_link = 'node/' . $context->data->etid; + } + // Build up an array for menu in levels + $conf['menu_name'] = $menu->mname; + $conf['parent_mlid'] = $menu->mname . ':0'; + $conf['delta'] = 1; + $conf['sort'] = FALSE; + $conf['title_link'] = FALSE; + $conf['follow'] = FALSE; + + $rendered_menu = menu_tree_build($conf); + $block->content = $rendered_menu['content']; + return $block; + } + // If no menu was found return + else { + return FALSE; + } +} + +/** + * 'Edit form' callback for the content type. + */ +function og_menu_pane_content_type_edit_form($form, &$form_state) { + $conf = $form_state['conf']; + + $form['og_menu_pane_block_links'] = array( + '#type' => 'checkbox', + '#title' => t('Link the title to group node'), + '#default_value' => !empty($conf['og_menu_pane_block_links']) ? $conf['og_menu_pane_block_links'] : '', + '#prefix' => '