June 2, 2008

Drupal: Adding lines to settings.php in an installation profile

June 2, 2008 - Categories: drupal, geek

Installation profiles can make it easier for you to test and reproduce your configuration. But what if you need to do more than what Install Profile Wizard detects? For example, parts of the Domain Access module ask you to add lines to your sites/default/settings.php. Fortunately, PHP allows you to set up your install profile to write to files during installation.

Here’s the code I added to the end of the profilename_profile_final() function:

    // Add the following to the end of settings.php
    $file = fopen("sites/default/settings.php", "a");
    if ($file) {
      fputs($file, "\$cookie_domain = '.transitions2.org';\n");
      fputs($file, "require_once './sites/all/modules/domain/domain_conf/settings_domain_conf.inc';\n");
      fputs($file, "require_once './sites/all/modules/domain/domain_prefix/settings_domain_prefix.inc';\n");
    } else {
      drupal_set_message("Can't add domain-related lines to sites/default/settings.php");

Hope it helps!

Drupal: Storing data in the user profile

June 2, 2008 - Categories: drupal

If you want to store data in the user profile, here’s an example of a quick and dirty way to do it:

global $user;
if ($user) {
  $array = array('fieldname' => 'value_to_save');
  user_save($user, $array);

Then access it with $user->fieldname. For more configurability, check out the Profile module.

Drupal makes me feel like Bruce Lee + Jackie Chan

June 2, 2008 - Categories: drupal, sketches

Fast. Powerful. And having a heck of a lot of fun.