diff --git a/includes/form.inc b/includes/form.inc index 4fabc4bf459973ee7c8f403baa93c8b5e3fe1390..126b7641efd0181009747b03275edd031263ac6f 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -72,7 +72,7 @@ function og_subgroups_add_group_select_form(&$form, $node) { '#type' => 'select', '#title' => $title, '#default_value' => $parent_id, - '#options' => og_subgroups_group_select_options(), + '#options' => og_subgroups_group_select_options(TRUE), '#description' => $description, ); } @@ -89,7 +89,7 @@ function og_subgroups_add_group_select_form(&$form, $node) { * @return * A keyed array used for a form select widget */ -function og_subgroups_group_select_options($indent = '--') { +function og_subgroups_group_select_options($only_enabled = FALSE, $indent = '--') { og_subgroups_include('tree'); $options = array(); @@ -109,7 +109,7 @@ function og_subgroups_group_select_options($indent = '--') { } // Add the groups that don't have children - $options += _og_subgroups_group_select_options_without_family(); + $options += _og_subgroups_group_select_options_without_family($only_enabled); // Add no parent as a selection option $options = array(t('')) + $options; @@ -139,8 +139,12 @@ function _og_subgroups_group_select_options_recursive(&$options, $branch, $inden /** * Helper function to generate a list of select options of groups * that do not have a hierarchy, meaning they are not in a family + * + * @param $only_enabled + * If TRUE, only return groups which are subgroups-enabled. Defaults + * to FALSE. */ -function _og_subgroups_group_select_options_without_family() { +function _og_subgroups_group_select_options_without_family($only_enabled = FALSE) { og_subgroups_include('tree'); $options = array(); @@ -149,6 +153,10 @@ function _og_subgroups_group_select_options_without_family() { // Iterate the groups foreach ($groups as $group) { + // Make sure this type is subgroups-enabled, if we're checking + if ($only_enabled && !og_subgroups_is_subgroup_type($group->type)) { + continue; + } // Check for access if (!og_subgroups_mask_group($group, TRUE)) { $options[$group->nid] = $group->title; diff --git a/includes/tree.inc b/includes/tree.inc index 0bd59dd9491948fbc1357dad515ff271c559d8cf..60260bcf1980902bace763cc99afa547d85bc4b9 100644 --- a/includes/tree.inc +++ b/includes/tree.inc @@ -407,7 +407,7 @@ function _og_subgroups_get_group_siblings_recursive($group, $branch) { * @return * An array of groups that are not part of a group hierarchy */ -function og_subgroups_get_groups_without_family() { +function og_subgroups_get_groups_without_family($only_enabled = TRUE) { $groups = array(); $sql = "SELECT og.nid, og.og_private, og.og_selective, n.title, n.status, n.type"; @@ -421,10 +421,7 @@ function og_subgroups_get_groups_without_family() { // Put the groups in array format while ($group = db_fetch_object($results)) { - // Make sure this type is enabled - if (og_subgroups_is_subgroup_type($group->type)) { - $groups[$group->nid] = $group; - } + $groups[$group->nid] = $group; } return $groups; diff --git a/modules/og_subgroups_hs/og_subgroups_hs.module b/modules/og_subgroups_hs/og_subgroups_hs.module index 9df5dcee461b59b4c19b086ca65306494e19451a..135025f45be8c32dbc87121143e6a09d32a37eef 100644 --- a/modules/og_subgroups_hs/og_subgroups_hs.module +++ b/modules/og_subgroups_hs/og_subgroups_hs.module @@ -154,7 +154,7 @@ function og_subgroups_hs_hierarchical_select_lineage($item, $params) { * Implementation of hook_hierarchical_select_valid_item(). */ function og_subgroups_hs_hierarchical_select_valid_item($item, $params) { - if($item == OG_SUBGROUPS_HS_ANY_OPTION) { + if ($item == OG_SUBGROUPS_HS_ANY_OPTION) { return TRUE; } diff --git a/og_subgroups.module b/og_subgroups.module index 49cd918ffe9d4d199dd21e11bfffa6f380d4d027..0c2ebdbc95efd50d8e98e75df3f1facd6350dc28 100644 --- a/og_subgroups.module +++ b/og_subgroups.module @@ -64,26 +64,12 @@ function og_subgroups_form_alter(&$form, &$form_state, $form_id) { if (og_is_group_post_type($node->type)) { // Override the default group audience select list to show hierarchy if (is_array($form['og_nodeapi']['visible']['og_groups']['#options'])) { - // Get a flat list of subgroups - $tree = og_subgroups_get_tree(); - $flat_tree = og_subgroups_flatten_tree($tree); - - // Remove subgroups from My Groups and Other Groups - if (is_array($form['og_nodeapi']['visible']['og_groups']['#options']['My groups'])) { - $mygroups = array_diff_key($form['og_nodeapi']['visible']['og_groups']['#options']['My groups'], $flat_tree); - $form['og_nodeapi']['visible']['og_groups']['#options']['My groups'] = $mygroups; - } - if (is_array($form['og_nodeapi']['visible']['og_groups']['#options']['Other groups'])) { - $othergroups = array_diff_key($form['og_nodeapi']['visible']['og_groups']['#options']['Other groups'], $flat_tree); - $form['og_nodeapi']['visible']['og_groups']['#options']['Other groups'] = $othergroups; - } - // Fetch the list of available groups indented with hierarchy - $subgroups = og_subgroups_group_select_options(); + $groups = og_subgroups_group_select_options(); // Remove the unneeded default option - unset($subgroups[0]); - // Add the subgroups to the audience field - $form['og_nodeapi']['visible']['og_groups']['#options']['Subgroups'] = $subgroups; + unset($groups[0]); + // Replace the groups with our list + $form['og_nodeapi']['visible']['og_groups']['#options'] = $groups; } } }