You are here

function _spaces_form_alter_node in Spaces 5

1 call to _spaces_form_alter_node()
spaces_form_alter in ./spaces.module

File

./spaces.module, line 271

Code

function _spaces_form_alter_node(&$form) {
  global $user;

  // 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) {
        $default_gid = is_array($form['#node']->og_groups) ? current($form['#node']->og_groups) : spaces_gid();
        $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.'),
        );
      }
    }
  }
  if (spaces_router('node form', $form['#node'])) {

    // Recurse into og_options hiding all of them.
    _spaces_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;
    }
  }
  else {
    drupal_access_denied();
    exit;
  }
}