You are here

function og_ui_confirm_subscribe in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og_ui/og_ui.pages.inc \og_ui_confirm_subscribe()

Confirm subscribe form.

1 string reference to 'og_ui_confirm_subscribe'
og_ui_subscribe in og_ui/og_ui.pages.inc
Subscribe the current user to a group.

File

og_ui/og_ui.pages.inc, line 125
Page callbacks for Organic groups module.

Code

function og_ui_confirm_subscribe($form, &$form_state, $group_type, $gid, $account, $field_name) {
  $wrapper = entity_metadata_wrapper($group_type, $gid);

  // Indicate the OG membership state (active or pending).
  $state = og_user_access($group_type, $gid, 'subscribe without approval') ? OG_STATE_ACTIVE : OG_STATE_PENDING;
  if ($wrapper
    ->access('view')) {
    $label = $wrapper
      ->label();
  }
  else {
    $label = t('Private group');
    if ($state == OG_STATE_ACTIVE) {

      // Determine if a user can subscribe to a private group, when OG-access
      // module is enabled, and the group is set to private.
      $state = variable_get('og_ui_deny_subscribe_without_approval', TRUE) ? OG_STATE_PENDING : OG_STATE_ACTIVE;
    }
  }

  // Add group membership form.
  $og_membership = og_membership_create($group_type, $gid, 'user', $account->uid, $field_name, array(
    'state' => $state,
  ));
  $form_state['og_membership'] = $og_membership;
  field_attach_form('og_membership', $og_membership, $form, $form_state);
  if ($state == OG_STATE_ACTIVE && !empty($form[OG_MEMBERSHIP_REQUEST_FIELD])) {

    // Hide the user request field.
    $form[OG_MEMBERSHIP_REQUEST_FIELD]['#access'] = FALSE;
  }
  $form['group_type'] = array(
    '#type' => 'value',
    '#value' => $group_type,
  );
  $form['gid'] = array(
    '#type' => 'value',
    '#value' => $gid,
  );
  $form['field_name'] = array(
    '#type' => 'value',
    '#value' => $field_name,
  );
  return confirm_form($form, t('Are you sure you want to join the group %title?', array(
    '%title' => $label,
  )), $wrapper->url
    ->value(), ' ', t('Join'), t('Cancel'));
}