How to set admin account username and email address in an install profile

This is a snippet from our current distribution's install profile. The password is set later with another helper function.

  1. /**
  2.  * Implementation of hook_form_alter().
  3.  *
  4.  * Allows the profile to alter the site-configuration form. This is
  5.  * called through custom invocation, so $form_state is not populated.
  6.  */
  7. function cws_d6_form_alter(&$form, $form_state, $form_id) {
  8. if ($form_id == 'install_configure') {
  9. // echo '<pre>';
  10. // print_r($form);
  11. // echo '</pre>';
  12. // Set default for site name field.
  13. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];
  14. $form['site_information']['site_mail']['#default_value'] = 'noreply@example.edu';
  15. $form['admin_account']['account']['name']['#default_value'] = 'username';
  16. $form['admin_account']['account']['mail']['#default_value'] = 'username@example.edu';
  17. $form['admin_account']['account']['pass']['#access'] = FALSE;
  18. $form['admin_account']['account']['pass']['#required'] = FALSE;
  19.  
  20. // autosubmit form
  21. $form['#post']['site_information'] = $form['site_information'];
  22. $form['#post']['admin_account'] = $form['admin_account']; $form['#post']['server_settings'] = $form['server_settings'];
  23. $form['#post']['clean_url'] = $form['clean_url'];
  24. $form['#post']['update_status_module'] = $form['update_status_module'];
  25. $form['#post']['submit'] = $form['submit'];
  26. $form['#post']['#action'] = $form['#action'];
  27.  
  28. drupal_prepare_form($form_id, $form, $form);
  29. drupal_process_form($form_id, $form, $form);
  30. }
  31. }