You are here

function invite_form_alter in Invite 7.2

Same name and namespace in other branches
  1. 5.2 invite.module \invite_form_alter()
  2. 5 invite.module \invite_form_alter()
  3. 6.2 invite.module \invite_form_alter()

Implements hook_form_alter().

File

./invite.module, line 374
Allows your users to send and track invitations to join your site.

Code

function invite_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_admin_settings':

      // Add new registration mode 'by invitation only'. By prepending the
      // option value with a numeric value, other modules still work as
      // expected, as long as they are using the non-strict PHP comparison
      // operator (since '1-inviteonly' == 1 yields TRUE). To determine the real
      // setting use invite_user_registration_by_invite_only().
      //
      // However, setting the new mode is only allowed if no other module
      // has overridden the menu access handler for the user registration form.
      $item = menu_get_item('user/register');
      if (in_array($item['access_callback'], array(
        'user_register_access',
        'invite_user_register_access',
      ))) {
        $form['registration_cancellation']['user_register']['#options'][USER_REGISTER_INVITATION_ONLY] = t('Invitees only');
      }

      // Clear menu cache on submit to allow our custom access handler to
      // snap in.
      $form['#submit'][] = 'menu_rebuild';
      break;
    case 'user_register_form':

      // In order to prevent caching of the preset e-mail address, we have to
      // disable caching for user/register.
      $GLOBALS['conf']['cache'] = FALSE;
      $invite = invite_load_from_context();
      if (!empty($invite) && invite_validate($invite) == INVITE_VALID) {

        // Preset the e-mail field.
        if (isset($form['account'])) {
          $field =& $form['account'];
        }
        else {
          $field =& $form;
        }
        if (isset($field['mail'])) {
          $field['mail']['#default_value'] = $invite->email;
        }

        // Enable/disable account depending on whether approval is required for invitees.
        $form['account']['status']['#default_value'] = !variable_get('invite_require_approval', FALSE);
      }
      break;
    case 'user_login_block':

      // Remove temptation for non members to try and register.
      if (invite_user_registration_by_invite_only()) {
        $new_items = array();
        $new_items[] = l(t('Request new password'), 'user/password', array(
          'attributes' => array(
            'title' => t('Request new password via e-mail.'),
          ),
        ));
        $form['links'] = array(
          '#markup' => theme('item_list', array(
            'items' => $new_items,
          )),
        );
      }
      break;
  }
}