You are here

function og_group_form in Organic groups 5.3

Same name and namespace in other branches
  1. 5.8 og.module \og_group_form()
  2. 5 og.module \og_group_form()
  3. 5.2 og.module \og_group_form()
  4. 5.7 og.module \og_group_form()
  5. 6.2 og.module \og_group_form()
  6. 6 og.module \og_group_form()

Adds standard fields for any node configured to be a group node

Parameters

object $node:

1 call to og_group_form()
og_form_alter in ./og.module

File

./og.module, line 1173

Code

function og_group_form($node) {
  global $user;
  $edit = $_POST['edit'];
  $form['og_description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#default_value' => $node->og_description,
    '#size' => 70,
    '#maxlength' => 150,
    '#required' => true,
    '#description' => t('A brief description for the group details block and the group directory.'),
    '#weight' => -4,
  );
  if ($node->nid) {
    $default = $node->og_selective;
  }
  else {
    $default = OG_OPEN;
  }
  $form['og_selective'] = array(
    '#type' => 'radios',
    '#title' => t('Membership requests'),
    '#required' => TRUE,
    '#default_value' => $default,
    '#options' => array(
      t('open - membership requests are accepted immediately.'),
      t('moderated - membership requests must be approved.'),
      t('invite only - membership must be created by an administrator.'),
      t('closed - membership is exclusively managed by an administrator.'),
    ),
    '#description' => t('How should membership requests be handled in this group? When you select <em>closed</em>, users will not be able to join <strong>or</strong> leave.'),
  );

  // registration checkbox
  // get the visibility for normal users
  $visibility = variable_get('og_visibility_registration', OG_REGISTRATION_CHOOSE_FALSE);

  // admin can always choose - get right default
  if (user_access('administer nodes')) {
    $visibility = in_array($visibility, array(
      OG_REGISTRATION_NEVER,
      OG_REGISTRATION_CHOOSE_FALSE,
    )) ? OG_REGISTRATION_CHOOSE_FALSE : OG_REGISTRATION_CHOOSE_TRUE;
  }
  $default = FALSE;
  switch ($visibility) {
    case OG_REGISTRATION_NEVER:
      $form['og_register'] = array(
        '#type' => 'value',
        '#value' => 0,
      );
      break;
    case OG_REGISTRATION_ALWAYS:
      $form['og_register'] = array(
        '#type' => 'value',
        '#value' => 1,
      );
      break;
    case OG_REGISTRATION_CHOOSE_TRUE:
      $default = TRUE;

    // fall through
    case OG_REGISTRATION_CHOOSE_FALSE:
      $form['og_register'] = array(
        '#type' => 'checkbox',
        '#title' => t('registration form'),
        '#default_value' => $node->nid ? $node->og_register : $default,
        '#description' => t('Should users be able to join this group during registration?. If checked, a corresponding checkbox will be added to the registration form.'),
      );
      break;
  }

  // directory checkbox
  $visibility = variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_TRUE);

  // override for admins - get right default
  if (user_access('administer nodes')) {
    $visibility = in_array($visibility, array(
      OG_DIRECTORY_NEVER,
      OG_DIRECTORY_CHOOSE_FALSE,
    )) ? OG_DIRECTORY_CHOOSE_FALSE : OG_DIRECTORY_CHOOSE_TRUE;
  }
  $default = FALSE;
  switch ($visibility) {
    case OG_DIRECTORY_NEVER:
      $form['og_directory'] = array(
        '#type' => 'value',
        '#value' => 0,
      );
      break;
    case OG_DIRECTORY_ALWAYS:
      $form['og_directory'] = array(
        '#type' => 'value',
        '#value' => 1,
      );
      break;
    case OG_DIRECTORY_CHOOSE_TRUE:
      $default = TRUE;

    // fall through
    case OG_DIRECTORY_CHOOSE_FALSE:
      $form['og_directory'] = array(
        '#type' => 'checkbox',
        '#title' => t('list in groups directory'),
        '#default_value' => $node->nid ? $node->og_directory : $default,
        '#description' => t('Should this group appear on the !page?  Disabled if the group is set to <em>private group</em>.', array(
          '!page' => l(t('list of groups page'), 'og'),
        )),
      );
      break;
  }

  // language
  if (module_exists('locale') && ($languages = locale_supported_languages())) {
    if (count($languages['name']) > 1) {
      $languages['name'] = array_map('check_plain', $languages['name']);
      $form['locale']['og_language'] = array(
        '#type' => 'radios',
        '#title' => t('Language'),
        '#default_value' => $node->og_language,
        '#options' => $languages['name'],
        '#description' => t('Selecting a different locale will change the interface language of the group. Users who have chosen a preferred language always see their chosen language.'),
      );
    }
  }
  if ($theme_form = system_theme_select_form(t('Selecting a different theme will change the look and feel of the group.'), $edit['theme'] ? $edit['theme'] : $node->og_theme, 2)) {
    $theme_form['themes']['#weight'] = 8;
    $form += $theme_form;
  }
  return $form;
}