You are here

function og_subgroups_form_alter in Subgroups for Organic groups 6

Same name and namespace in other branches
  1. 5.3 og_subgroups.module \og_subgroups_form_alter()

Implenentation of hook_form_alter().

File

./og_subgroups.module, line 49
Maintains a hierarchy of groups created by the orgainc groups module.

Code

function og_subgroups_form_alter(&$form, &$form_state, $form_id) {

  // If on a node form
  if ($form['#id'] == 'node-form') {

    // Extract the node
    if ($node = $form['#node']) {

      // Include our form functions
      og_subgroups_include('form');

      // See if this is a group
      if (og_is_group_type($node->type)) {

        // Add the subgroup fields to the node form
        og_subgroups_add_group_select_form($form, $node);
      }

      // See if this is a group post
      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'])) {

          // Fetch the list of available groups indented with hierarchy
          $groups = og_subgroups_group_select_options();

          // Remove the unneeded default option
          unset($groups[0]);

          // Replace the groups with our list
          $form['og_nodeapi']['visible']['og_groups']['#options'] = $groups;
        }
      }
    }
  }
}