diff --git a/sites/all/modules/og_menu/og_menu.info b/sites/all/modules/og_menu/og_menu.info index e75b39a..27ba854 100644 --- a/sites/all/modules/og_menu/og_menu.info +++ b/sites/all/modules/og_menu/og_menu.info @@ -5,6 +5,7 @@ dependencies[] = menu dependencies[] = og (2.x) dependencies[] = og_ui dependencies[] = og_context +dependencies[] = menu_block configure = admin/config/group/og_menu package = "Organic groups" core = 7.x diff --git a/sites/all/modules/og_menu/og_menu.module b/sites/all/modules/og_menu/og_menu.module index 5a3a22a..178c0d2 100644 --- a/sites/all/modules/og_menu/og_menu.module +++ b/sites/all/modules/og_menu/og_menu.module @@ -199,6 +199,16 @@ function og_menu_menu() { } /** + * Implementation of hook_ctools_plugin_dierctory() to let the system know + * where our content_type plugins are. + */ +function og_menu_ctools_plugin_directory($module, $plugin) { + if ($module == 'ctools' && !empty($plugin)) { + return "plugins/$plugin"; + } +} + +/** * Implements hook_theme_registry_alter(). */ function og_menu_theme_registry_alter(&$theme_registry) { diff --git a/sites/all/modules/og_menu/plugins/content_types/og_menu_pane_content_type.inc b/sites/all/modules/og_menu/plugins/content_types/og_menu_pane_content_type.inc new file mode 100644 index 0000000..3f7562a --- /dev/null +++ b/sites/all/modules/og_menu/plugins/content_types/og_menu_pane_content_type.inc @@ -0,0 +1,160 @@ + 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' => t('Organic groups'), + // Optionally pass in the node context. If no context is selected, + // we will try to determine the group from the args passed. + 'required context' => new ctools_context_optional(t('Node'), 'node'), +); + +/** + * 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 node, if this is empty we will see if + * there is a gid passed in args. + * + * @return + * object An object with at least title and content members. + */ +function og_menu_pane_content_type_render($subtype, $conf, $args, $context) { + + // grabs the gid from the node's group ref field (for group content nodes) + if(isset($context->data->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0])) { + $gid = $context->data->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]; + } + + // this should be true for group nodes + elseif(isset($context->data->{OG_GROUP_FIELD})) { + $gid = $context->data->nid; + } + + // if we are using something like a view, and passing in the gid + // through the URL, then the argument should hold the gid. This also + // should be true for the group node if no context was selected. + elseif(!empty($args)) { + if(og_is_group('node', $args[0])) { + $gid = intval($args[0]); + } + else { + return FALSE; + } + } + else { + return FALSE; + } + + // Get the OG menu for the group. + $groups = array('node' => array($gid)); + $menus = og_menu_get_group_menus($groups); + $menu = array_shift($menus); + + if ($menu) { + $block = new stdClass(); + $block->title = check_plain($menu['title']); + // 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['menu_name']; + $conf['parent_mlid'] = $menu['menu_name'] . ':0'; + $conf['delta'] = 1; + $conf['sort'] = FALSE; + $conf['title_link'] = FALSE; + $conf['follow'] = FALSE; + $conf['expanded'] = isset($conf['expanded']) ? $conf['expanded'] : FALSE; + $conf['level'] = isset($conf['level']) ? $conf['level'] : 1; + $conf['depth'] = isset($conf['depth']) ? $conf['depth'] : 1; + $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]; + } + } +}