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..3f16897 --- /dev/null +++ b/plugins/content_types/og_menu_pane_content_type.inc @@ -0,0 +1,180 @@ + 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 pane. + '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['og_menu_index'] = !empty($conf['og_menu_index']) ? $conf['og_menu_index'] : 1; + $menu = $menus[$conf['og_menu_index'] - 1]; + + if ($menu) { + $pane = new stdClass(); + $pane->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']) { + $pane->title_link = 'node/' . $gid; + } + if (module_exists('menu_block')) { + // 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); + $pane->content = $rendered_menu['content']; + } + else { + $pane->content = menu_tree($menu['menu_name']); + } + return $pane; + } + // 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' => '