Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a installation profile, how do I fill values for Set up database step programmatically and hide it so user doesn't need to fill the form?

How to do the above action for the Select language step?

share|improve this question
up vote 3 down vote accepted
+50

You wanted an example -- which is basically showing you how to do it. From the docs I supplied and the help others that gave you cookie crumbs provided should have lead you towards a solution, Other than saying "show me" all the code.

A working profile example is in this GIST, you make a shortprofile directory in your /profiles directory and select "Short Profile" from the Installation screen. This is the "long way" to do this, there is a shorter way in-theory ... see my code comments.

Be sure to change the $databases['default']['default'] in line 47 of .profile to the existing database credentials that will work in your environment. Look for my comments in the code to change the db credentials and db password (line 125 of .profile).

share|improve this answer
    
for the Locale stuff I would do a custom system_form_install_select_locale_form_alter() in your .profile file and provide the default value you want. – tenken Mar 29 '12 at 22:52

Fair warning I haven' done this before (but I have made install profiles and used them via Drush Make). So I was interested in how you might try to do this ...

I found this documentation page, How To Write a Drupal 7 Installation Profile

I assume you are using the 'Miminal' or 'Standard' defaults in your profile to save you some headache, or else you'd know the answer to your own question in building a complete profile from scratch ... I think you need to do 2 things:

(1) If you're using the minimal or standard defaults you can use hook_install_tasks_alter() to change the visibility of the database Step to hidden. If your defining your own install tasks via hook_install_tasks() in yourprofile.profile

(2) You need to provide the database parameters. You can do that probably most straight-forwardly via hook_form_alter() as described in the documentation page linked above. You may also be able to muck with the values in $install_state for hook_install_tasks as described in install_state_defaults()

I suggest you read up on all these hook functions and the documentation page above. good luck.

share|improve this answer
    
Thanks, I know about hooks you mentioned. I need more details on how to set database parameters. – hknik Mar 29 '12 at 14:46

Database credentials are set in settings.php. So you'd provide a settings.php with your distribution, or you'd write out the db array to the settings.php at some point during installation.

You could do this in an installation profile, with hook_install_tasks_alter(), by changing install_settings_form.

Same caveats as tenken... I haven't done this.

share|improve this answer
1  
I have done this, and it works; Drupal will skip the database configuration page on install if the database settings are already configured in settings.php. I have not tried this on D7 (I mostly use drush site-install nowadays), but it should still work. One problem on D6 which may or may not be fixed on D7: if you navigate to mysite.org when it is NOT installed, then you will see many errors; you must go to mysite.org/install.php directly. – greg_1_anderson Mar 29 '12 at 18:19
    
"You could do this in an installation profile, with hook_install_tasks_alter(), by changing install_settings_form." This is my question! how to do this with hook_install_tasks_alter()? Can you provide an example? – hknik Mar 29 '12 at 18:45
    
as @greg_1_anderson says using settings.php causes errors until user enters example.com/install.php – hknik Mar 29 '12 at 18:47
    
Right. That's how you install Drupal. :-) – paul-m Apr 7 '12 at 17:48

For me the accepted answer didn't work. It would just fill the form with default values but the user would still need to click to "save configuration" button to go forward. This is not what I would call a "skip step" if the user still has to press a button.

But basing on the solution I could find something that worked for me. First alter the step in question in your_profile_install_tasks_alter

your_profile_install_tasks_alter(&$tasks, $install_state) {
  $tasks['install_settings_form']['display'] = FALSE;
  $tasks['install_settings_form']['function'] = 'your_profile_install_settings_defaults';
  $tasks['install_settings_form']['type'] = 'normal';
}

Setting the type to form gave me problems as I was trying to call drupal_form_submit (would complain function is undefined) and overcomplicating my life

Now just copy paste the code from the submit function from core:

function your_profile_install_settings_defaults(&$install_state) {

  $database = array(
    'database' => 'yourparams',
    'username' => 'yourparams',
    'password' => 'yourparams',
    'prefix' => '',
    'host' => 'localhost',
    'port' => '',
    'driver' => 'mysql'
  );

  // Update global settings array and save.
  $settings['databases'] = array(
    'value' => array('default' => array('default' => $database)),
    'required' => TRUE,
  );
  $settings['drupal_hash_salt'] = array(
    'value' => drupal_hash_base64(drupal_random_bytes(55)),
    'required' => TRUE,
  );
  drupal_rewrite_settings($settings);
  // Indicate that the settings file has been verified, and check the database
  // for the last completed task, now that we have a valid connection. This
  // last step is important since we want to trigger an error if the new
  // database already has Drupal installed.
  $install_state['settings_verified'] = TRUE;
  $install_state['completed_task'] = install_verify_completed_task();
  return NULL;
}

That worked for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.