You are here

function comment_og_form_alter in Comment OG 6

Same name and namespace in other branches
  1. 5 comment_og.module \comment_og_form_alter()

File

./comment_og.module, line 110

Code

function comment_og_form_alter(&$form, $form_state, $form_id) {
  $group = og_get_group_context();

  // if group context
  if ($group) {

    /* Support disabling the comment form on a forum node */
    if ($form_id == 'comment_form' && isset($form['nid'])) {

      /*
       * If this is group context and you're not a member of this
       * group and this group doesn't allow non-members to post,
       * disable the comment form.
       */
      $og_node = og_get_group_context();
      if (!comment_og_access($og_node)) {
        $form['comment_filter']['comment'] = array(
          '#type' => 'textarea',
          '#title' => t('Comment'),
          '#rows' => 5,
          '#disabled' => TRUE,
          '#description' => t('You must be a member of this group in order to post a comment.'),
        );
        if (isset($form['subject'])) {
          unset($form['subject']);
        }
        if (isset($form['comment_filter']['format'])) {
          unset($form['comment_filter']['format']);
        }
        if (isset($form['submit'])) {
          unset($form['submit']);
        }
        if (isset($form['preview'])) {
          unset($form['preview']);
        }
        if (isset($form['author'])) {
          unset($form['author']);
        }
        if (isset($form['_author'])) {
          unset($form['_author']);
        }
      }
    }

    /* Alter the group node's form to add non-member access configuration */
    if (isset($form['#node']) && $form_id == $form['#node']->type . '_node_form' && og_is_group_type($form['#node']->type)) {
      $node = $form['#node'];
      if (variable_get('comment_og_admin_nonmember_access', FALSE)) {
        $form['comment_og_nonmember_access'] = array(
          '#title' => t('Allow non-member comments'),
          '#description' => t('Allow non-members to post comments in this group.'),
          '#type' => 'checkbox',
          '#default_value' => _comment_og_allow_nonmember_access($node->nid),
          '#access' => og_is_group_admin($node),
          '#weight' => 1 + module_exists('content') ? content_extra_field_weight($node->type, 'og_selective') : 0,
        );
      }
    }
  }
}