You are here

function oa_users_external_user_form_submit in Open Atrium Core 7.2

Submit handler for adding member.

_state

Parameters

$form:

Return value

mixed

1 string reference to 'oa_users_external_user_form_submit'
oa_users_external_user_form in modules/oa_users/plugins/content_types/oa_users_add_external_user.inc

File

modules/oa_users/plugins/content_types/oa_users_add_external_user.inc, line 209

Code

function oa_users_external_user_form_submit($form, &$form_state) {
  if (($account = $form['#user']) && ($group = $form['#group'])) {

    // This is an oa_space or oa_group type.
    if ($group->type == OA_SPACE_TYPE || $group->type == OA_GROUP_TYPE) {

      // Add the member to the space.
      oa_core_add_member_api('node', $group->nid, $account->uid);
    }
    else {
      if ($group->type == OA_TEAM_TYPE) {

        // Load the space the team belongs to.
        $space_nid = oa_core_get_group_from_node($group);

        // Add the member to the space.
        oa_core_add_member_api('node', $space_nid, $account->uid);

        // Add the member to the team.
        oa_teams_add_member($group, $account->uid);

        // A message gets set for the space. We need to add one for the team as well. Use the 'Display name' so we match
        // the message added when adding a user to a space.
        $wrapper = entity_metadata_wrapper('user', $account);

        // Get the 'Display Name' instead of using the actual name.
        $name = $wrapper->field_user_display_name
          ->value();
        drupal_set_message(t('@name has been added to the team @team.', array(
          '@name' => $name,
          '@team' => $group->title,
        )));
      }
    }
  }
  else {

    // Something went wrong with creating the user.
    drupal_set_message(t('There was an error creating the user. Please contact your group administrator.'), 'error');
  }
}