3

I'm writing a custom installation profile, and most things work, except that I can't get it to change the site name.

function myprofile_install() {
  include_once DRUPAL_ROOT . '/profiles/standard/standard.install';
    standard_install();

    // ...

    variable_set('site_name', st('My Site Name'));

    // ...
}

the variable_set has no effect. So I tried adding

$GLOBALS['config']['site_name'] = "My Site Name";

at the end of the function to see if it got a different result, but it did not. Other parts of my profile work, so I know it's running. Other profiles seem to be able to use variable_set in their hook_install, so I don't think it's forbidden. Is there something else that I need to do to get the variables to "take"?

This question seems to indicate that I am doing it correctly, as do this one and this one. I've re-checed the RTFM and sample profiles to see if there's a step I'm missing, but if there is, I can't find it. The title of this question looked promising, but it turned out to be an unrelated issue.

If I add an echo statement inside of myprofile_install it indicates that the value has been set properly (and that the myprofile_install function is being read all the way through), but when I log into the site, it has the default 'site-install' name.

I am building the site via a drush command, not via the gui:

drush -y si myprofile --db-url=mysql://###:###@localhost:8080/mysite username=### pass=### dbname=###

In response to @clive's comment (thanks!), I neglected to mention that I also have

function myprofile_form_install_configure_form_alter(&$form, $form_state) {
    if (!function_exists("system_form_install_configure_form_alter")) {
        function system_form_install_configure_form_alter(&$form, $form_state) {
            $form['site_information']['site_name']['#default_value'] = 'mysite';
        }
    }
 }

in the .profile file. I assumed this code wasn't being called at all, since I wasn't using the gui form. But if the form were invisibly clobbering the values I set in the .install file, it seems like it would be setting it to mysite rather than to site-install?

  • 2
    I think your changes are being clobbered by install_configure_form_submit(), which does this: variable_set('site_name', $form_state['values']['site_name']);. – Clive May 20 '15 at 18:31
  • 2
    Is it possible that drush installation uses the form submit function, but doesn't render the form and therefore doesn't pick up the alter hook? (thinking out loud) – Darvanen May 21 '15 at 0:20
0

The work-around that I'm currently using (because I really need to move on and accomplish other things) is to add a

drush -y vset site_name "My Site"

call to the bash script that I'm using to create the mysql database and run the installation. Not an elegant solution, (and it bypasses localization, but that's not an issue yet, since the site is currently in only one language), but it gets the job done for now so that I can get other things working.

Leaving this here in case it helps someone, but not "accepting" it, since it's a work-around, not an answer.

0

For Drupal 8 you need to perform this drush command:

drush config-set system.site name 'Project X'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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