5

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?

4 Answers 4

4
+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).

1
  • 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, 2012 at 22:52
2

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.

1
  • Thanks, I know about hooks you mentioned. I need more details on how to set database parameters.
    – hknik
    Mar 29, 2012 at 14:46
2

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.

1

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.

4
  • 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. Mar 29, 2012 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, 2012 at 18:45
  • as @greg_1_anderson says using settings.php causes errors until user enters example.com/install.php
    – hknik
    Mar 29, 2012 at 18:47
  • Right. That's how you install Drupal. :-)
    – paul-m
    Apr 7, 2012 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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