/** * Function to create a user in Drupal. * * @param array $params associated array * @param string $mail email id for cms user * * @return uid if user exists, false otherwise * * @access public * */ function createUser(&$params, $mail) { $form_state = form_state_defaults(); $form_state['input'] = array('name' => $params['cms_name'], 'mail' => $params[$mail], 'op' => 'Create new account'); $admin = user_access('administer users'); if (!variable_get('user_email_verification', TRUE) || $admin) { $form_state['input']['pass'] = array('pass1' => $params['cms_pass'], 'pass2' => $params['cms_pass']); } if (!empty($params['notify'])) { $form_state['input']['notify'] = $params['notify']; } $form_state['rebuild'] = FALSE; $form_state['programmed'] = TRUE; $form_state['complete form'] = FALSE; $form_state['method'] = 'post'; $form_state['build_info']['args'] = array(); /* * if we want to submit this form more than once in a process (e.g. create more than one user) * we must force it to validate each time for this form. Otherwise it will not validate * subsequent submissions and the manner in which the password is passed in will be invalid * */ $form_state['must_validate'] = TRUE; $config = CRM_Core_Config::singleton(); // we also need to redirect b $config->inCiviCRM = TRUE; $form = drupal_retrieve_form('user_register_form', $form_state); $form_state['process_input'] = 1; $form_state['submitted'] = 1; $form['#array_parents'] = array(); $form['#tree'] = FALSE; drupal_process_form('user_register_form', $form, $form_state); $config->inCiviCRM = FALSE; if (form_get_errors()) { return FALSE; } return $form_state['user']->uid; }
/** * Simulate action of pressing of an Add More button. This function processes * the form based on the specified inputs and updates the form with the new * values in the cache so that the form's submit button can work correctly. * * @param string $triggering_element_name * Name of the Add More button or value of Op key. * @param array $options * Options array. If key "ajax" is set to TRUE, then * $triggering_element_name is assumed to be name of the Add More button * otherwise it is taken to be the value of Op key. * * @return Response * Response object. */ public function pressButton($triggering_element_name = NULL, $options = array()) { $options += array('ajax' => FALSE); $ajax = $options['ajax']; // Make sure that a button with provided name exists. if ($ajax && !is_null($triggering_element_name) && !$this->buttonExists($triggering_element_name)) { return new Response(FALSE, NULL, "Button {$triggering_element_name} does not exist."); } if (!$ajax) { // If this is not an AJAX request, then the supplied name is the value of // Op parameter. $response = $this->fillOpValues($triggering_element_name); if (!$response->getSuccess()) { return $response; } } $this->clearErrors(); $this->makeUncheckedCheckboxesNull(); $this->removeFileFieldWeights(); $old_form_state_values = !empty($this->form_state['values']) ? $this->form_state['values'] : array(); $this->form_state = form_state_defaults(); $args = func_get_args(); // Remove $triggering_element_name from the arguments. array_shift($args); // Remove $options from the arguments. array_shift($args); $this->form_state['build_info']['args'] = $args; $this->form_state['programmed_bypass_access_check'] = FALSE; //$this->form_state['values']['form_build_id'] = $this->form['#build_id']; // Add more field button sets $form_state['rebuild'] to TRUE because of // which submit handlers are not called. Hence we set it back to FALSE. $this->removeKey('input'); $this->removeKey('triggering_element'); $this->removeKey('validate_handlers'); $this->removeKey('submit_handlers'); $this->removeKey('clicked_button'); $this->form_state['input'] = $old_form_state_values; $this->form_state['input']['form_build_id'] = $this->form['#build_id']; if (!is_null($triggering_element_name) && $ajax) { $this->form_state['input']['_triggering_element_name'] = $triggering_element_name; } $this->form_state['no_redirect'] = TRUE; $this->form_state['method'] = 'post'; //$this->form_state['programmed'] = TRUE; $this->form = drupal_build_form($this->form_id, $this->form_state); if ($ajax && !is_null($triggering_element_name)) { unset($this->form_state['values'][$triggering_element_name]); } // Reset the static cache for validated forms otherwise form won't go // through validation function again. drupal_static_reset('drupal_validate_form'); if ($errors = form_get_errors()) { $this->errors = $errors; return new Response(FALSE, NULL, implode(", ", $this->errors)); } return new Response(TRUE, NULL, ""); }