diff --git a/og_menu.info b/og_menu.info index 5c80d07..39297fc 100644 --- a/og_menu.info +++ b/og_menu.info @@ -2,6 +2,7 @@ name = OG Menu description = "Allow group creators and site admins to edit their own group menu." files[] = og_menu.module dependencies[] = menu +dependencies[] = menu_block dependencies[] = og (2.x) dependencies[] = og_ui dependencies[] = og_context diff --git a/og_menu.module b/og_menu.module index 3083a48..96ffa9d 100644 --- a/og_menu.module +++ b/og_menu.module @@ -35,7 +35,6 @@ function og_menu_og_permission() { /** * Implements hook_og_ui_get_group_admin(). - * */ function og_menu_og_ui_get_group_admin($group_type, $gid) { $items = array(); @@ -216,6 +215,17 @@ function og_menu_menu() { } /** + * Implements 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) { @@ -334,8 +344,8 @@ function og_menu_form_node_form_alter(&$form, &$form_state) { '#description' => t('Check to create a menu for this group. Uncheck to delete all menus associated with this group.'), ); // @todo If we're going to delete all of the groups menus, - // we should ask the user for confirmation - //$form['#submit'][] = 'og_menu_group_form_validate'; + // we should ask the user for confirmation + // $form['#submit'][] = 'og_menu_group_form_validate'; } if (og_is_group_content_type('node', $type) && variable_get('og_menu_enable_' . $type, FALSE)) { @@ -670,8 +680,8 @@ function og_menu_node_prepare($node) { foreach ($og_fields as $field_name => $label) { $field = field_info_field($field_name); $target_type = $field['settings']['target_type']; - // The handler delivers all available targets for each content type, skip - // the ids if we already have that type's results. + // The handler delivers all available targets for each content type, + // skip the ids if we already have that type's results. if (empty($groups[$target_type])) { $instance = field_info_instance('node', $field_name, $type); // Using the handler allows us to get user options from OG without @@ -682,9 +692,9 @@ function og_menu_node_prepare($node) { foreach ($ids as $key => $values) { $field_gids += $values; } - // Not ready yet, if a user has access to menus in one group, it does - // not mean we can give him access to the menus of all groups he has - // access to. + // Not ready yet, if a user has access to menus in one group, + // it does not mean we can give him access to the menus of + // all groups he has access to. if (!empty($field_gids) && !(user_access('administer menu') || user_access('administer og menu'))) { foreach ($field_gids as $gid => $name) { if (!og_user_access($target_type, $gid, 'administer og menu')) { @@ -911,6 +921,7 @@ function og_menu_get_group_menus($groups = NULL, $user = NULL) { $query ->fields('om', array('gid', 'group_type', 'menu_name')) ->fields('m', array('title')); + $query->orderBy('title', 'ASC'); $gids_condition = db_or(); foreach ($groups as $group_type => $group_gids) { diff --git a/og_menu.pages.inc b/og_menu.pages.inc index fb5cec8..afa8be3 100644 --- a/og_menu.pages.inc +++ b/og_menu.pages.inc @@ -25,7 +25,13 @@ function og_menu_overview_page($group_type, $gid) { ON om.menu_name = m.menu_name WHERE om.gid = :gid ORDER BY title", array(':gid' => $gid)); - $header = array(t('Title'), array('data' => t('Operations'), 'colspan' => '3')); + $header = array( + t('Title'), + array( + 'data' => t('Operations'), + 'colspan' => '3', + ), + ); $rows = array(); foreach ($result as $menu) { $row = array( @@ -203,7 +209,6 @@ function og_menu_edit_item_form($form, &$form_state, $type, $group_type, $gid, $ // Set the title of the page. drupal_set_title(t('Add item into menu !mtitle', array('!mtitle' => $menu['title'])), PASS_THROUGH); - // Build the form. $form['parent']['#options'] = menu_parent_options($list, array('mlid' => 0)); $form['og_menu_group_type'] = array( @@ -276,7 +281,7 @@ function og_menu_config_form($form, &$form_state) { '#description' => t('If enabled, an OG Menu will be created by default when a new Organic Group node is created.'), ); - + $form['og_menu_context_limit'] = array( '#type' => 'checkbox', '#title' => t('Limit available menus to provided context'), diff --git a/plugins/content_types/og_menu_pane_content_type.inc b/plugins/content_types/og_menu_pane_content_type.inc new file mode 100644 index 0000000..2efbb92 --- /dev/null +++ b/plugins/content_types/og_menu_pane_content_type.inc @@ -0,0 +1,168 @@ + t('OG Menu pane'), + 'description' => t('This pane renders a OG Menu'), + // 'single' => TRUE means has no subtypes. + 'single' => TRUE, + // Constructor. + 'content_types' => array('og_menu_pane_content_type'), + // 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'), +); + +/** + * Output function for the og_menu pane content type. + */ +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]['target_id']; + } + + // 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); + $conf['menu_index'] = isset($conf['menu_index']) ? $conf['menu_index'] : 0; + $menu = $menus[$conf['menu_index']]; + + 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/' . $gid; + } + // 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['menu_index'] = array( + '#type' => 'select', + '#title' => t('Menu index'), + '#default_value' => $conf['menu_index'], + '#options' => array( + '0' => t('First Menu'), + '1' => t('Second Menu'), + '2' => t('Third Menu'), + ), + '#description' => t('Select the menu to display.'), + ); + $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]; + } + } +}