You are here

function user_external_invite_form_alter in User External Invite 7

Same name and namespace in other branches
  1. 7.2 user_external_invite.module \user_external_invite_form_alter()
  2. 1.0.x user_external_invite.module \user_external_invite_form_alter()

Implements hook_form_alter().

If there are still invites pending, then changing anything related to roles could interfere with the invite process. Users should get a warning message to proceed with caution.

Parameters

array $form: The form array passed to form_alter().

array $form_state: The values of the current form's state.

File

./user_external_invite.module, line 940
Invites a user to site when connecting via external protocol e.g. LDAP.

Code

function user_external_invite_form_alter(&$form, &$form_state) {

  // Only alter the roles and permissions forms.
  if ($form['#form_id'] == 'user_admin_permissions' || $form['#form_id'] == 'user_admin_roles') {

    // Check to see if any invites are pending and
    // what role ids are associated with them.
    if ($role_ids = db_query('SELECT rid FROM {user_external_invite} WHERE status = :status', array(
      ':status' => 'Pending',
    ))
      ->fetchCol()) {

      // Print out role names to attach to warning message.
      $role_names = array_map(function ($a) {
        return _user_external_invite_role_name_from_rid($a);
      }, $role_ids);
      drupal_set_message(t('User Invites are still pending with roles of: :roles. Altering roles or permissions could interfere with the user invite process. Pending invites can be viewed at: :urls', array(
        ':roles' => implode(', ', $role_names),
        ':urls' => '<a href="' . base_path() . 'admin/people/invite">admin/people/invite</a>',
      )), 'warning');
    }
  }
}