You are here

function og_ui_unsubscribe in Organic groups 7

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

Confirm OG unsubscription form.

The unsubscribing user is always the acting user - like this we make sure no malicious user will unsubscribe another user. Administrators can reject or ban another group member from the "people" page.

1 string reference to 'og_ui_unsubscribe'
og_ui_menu in og_ui/og_ui.module
Implements hook_menu().

File

og_ui/og_ui.pages.inc, line 155
Page callbacks for Group module.

Code

function og_ui_unsubscribe($entity_type, $etid) {
  if ($group = og_get_group($entity_type, $etid)) {
    global $user;
    $label = og_label($group->gid);

    // Check the user isn't the manager of the group.
    $manager = $group
      ->user();
    if ($manager->uid != $user->uid) {
      $account = clone $user;
      if (og_is_member($group->gid, 'user', $account, array(
        OG_STATE_ACTIVE,
        OG_STATE_PENDING,
      ))) {

        // Show the user a subscription confirmation.
        return drupal_get_form('og_ui_confirm_unsubscribe', $group, $account);
      }
    }
    else {
      drupal_set_message(t('As the manager of %group, you can not leave the group.', array(
        '%group' => $label,
      )));
    }
    $entity = $group
      ->getEntity();
    _group_ui_redirect($group->entity_type, $entity);
  }

  // Not a valid group.
  drupal_not_found();
}