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' => '
', + '#suffix' => '
', + ); + $form['level'] = array( + '#type' => 'select', + '#title' => t('Starting level'), + '#default_value' => $conf['level'], + '#options' => array( + '1' => t('1st level (primary)'), + '2' => t('2nd level (secondary)'), + '3' => t('3rd level (tertiary)'), + '4' => t('4th level'), + '5' => t('5th level'), + '6' => t('6th level'), + '7' => t('7th level'), + '8' => t('8th level'), + '9' => t('9th level'), + ), + '#description' => t('Blocks that start with the 1st level will always be visible. Blocks that start with the 2nd level or deeper will only be visible when the trail to the active menu item is in the block’s tree.'), + ); + $form['depth'] = array( + '#type' => 'select', + '#title' => t('Maximum depth'), + '#default_value' => $conf['depth'], + '#options' => array( + '1' => '1', + '2' => '2', + '3' => '3', + '4' => '4', + '5' => '5', + '6' => '6', + '7' => '7', + '8' => '8', + '9' => '9', + 0 => t('Unlimited'), + ), + '#description' => t('From the starting level, specify the maximum depth of the menu tree.'), + ); + $form['expanded'] = array( + '#type' => 'checkbox', + '#title' => t('Expand all children of this tree.'), + '#default_value' => isset($conf['expanded']) ? $conf['expanded'] : 0, + ); + return $form; +} + +/** + * Submit callback for content type editing form. + */ +function og_menu_pane_content_type_edit_form_submit(&$form, &$form_state) { + foreach (array_keys($form_state['input']) as $key) { + if (!empty($form_state['values'][$key])) { + $form_state['conf'][$key] = $form_state['values'][$key]; + } + } +}