You are here

function _spaces_og_form_alter_node in Spaces 5.2

Same name and namespace in other branches
  1. 6.3 spaces_og/spaces_og.pages.inc \_spaces_og_form_alter_node()
  2. 6 spaces_og/spaces_og.module \_spaces_og_form_alter_node()
  3. 6.2 spaces_og/spaces_og.module \_spaces_og_form_alter_node()
  4. 7.3 spaces_og/spaces_og.pages.inc \_spaces_og_form_alter_node()
  5. 7 spaces_og/spaces_og.pages.inc \_spaces_og_form_alter_node()

Group-enabled node form_alter()

1 call to _spaces_og_form_alter_node()
spaces_og_form_alter in ./spaces_og.module

File

./spaces_og.module, line 639

Code

function _spaces_og_form_alter_node(&$form) {
  global $user;
  $space = spaces_get_space();

  // TODO: We need to present a different UI (actually, probably we don't
  // need one at all) if spaces_announce is enabled. We need to move this
  // check into spaces_announce to protect the modularity of Spaces.
  if (!module_exists('spaces_announce')) {

    // Give admins access to all group options
    if (user_access('administer organic groups')) {
      $options = array(
        t('My groups') => array(),
        t('All groups') => array(),
      );
      $options[t('All groups')] = _spaces_og_group_options($form['#node']->type);
      foreach (og_get_subscriptions($user->uid) as $node) {
        unset($options[t('All groups')][$node['nid']]);
        $options[t('My groups')][$node['nid']] = $node['title'];
      }
      if (empty($options[t('All groups')])) {
        unset($options[t('All groups')]);
      }
      if ($options) {
        if (is_array($form['#node']->og_groups) && isset($form['#node']->og_groups[0])) {
          $default_gid = $form['#node']->og_groups[0];
        }
        else {
          if ($space) {
            $default_gid = $space->sid;
          }
          else {
            $default_gid = NULL;
          }
        }
        $form['spaces_og'] = array(
          '#type' => 'fieldset',
          '#tree' => true,
          '#title' => t('Group'),
        );
        $form['spaces_og']['gid'] = array(
          '#type' => 'select',
          '#options' => $options,
          '#default_value' => $default_gid,
          '#description' => t('Please select a group to move this post to.'),
        );
      }
    }
  }

  // Recurse into og_options hiding all of them.
  _spaces_og_make_hidden($form['og_nodeapi']);
  $form['spaces'] = array(
    '#title' => t('Privacy'),
    '#type' => 'fieldset',
    '#weight' => 100,
  );
  switch ($form['#node']->og_public) {
    case OG_VISIBLE_GROUPONLY:
      $form['spaces']['#description'] = t('A post of this type is always <strong>private</strong>. Only members of this group will see it.');
      break;
    case OG_VISIBLE_BOTH:
      $form['spaces']['#description'] = t('A post of this type is always <strong>public</strong>. All visitors will see it.');
      break;
  }
}