blog

Small tips to Optimize your day PT II (drush, drush make and installation profiles)

July 13 2010 by Joseph Smith

One of the inherent weaknesses of Drupal is the setup time involved to get a project up and running. D7 has remedied this somewhat by adding many commonly used contributed modules to core, but the issue of setup/maintenance time does not stop there. drush and drush make can help to bridge the gaps in functionality that Drupal core leaves open.

drush makefiles

You can always download all of your commonly used modules for each project... or, you can do this as a one-off and grab everything once and automate later downloads by creating a drush makefile. The syntax is similar to Drupal .info files and descriptive so it's not too hard to translate what's going on.

below is a simplified sample file named standard.make. You can also, specify versions, code repositories, extra libraries (CKeditor comes to mind...), and other options for your modules.

; Core
; ----
 
core = 6.x
projects[] = drupal
 
; Contrib Mods
; ------------
 
projects[context][subdir] = "contrib"
projects[features][subdir] = "contrib"
 
projects[cck][subdir] = "contrib"
projects[imagefield][subdir] = "contrib"
projects[filefield][subdir] = "contrib"
projects[date][subdir] = "contrib"
 
projects[views][subdir] = "contrib"
projects[views_bulk_operations][subdir] = "contrib"
projects[menu_block][subdir] = "contrib"
projects[pathauto][subdir] = "contrib"
projects[rules][subdir] = "contrib"
projects[token][subdir] = "contrib"
 
projects[ckeditor][subdir] = "contrib"
projects[imce][subdir] = "contrib"
 
projects[image_fupload][subdir] = "contrib"
projects[imageapi][subdir] = "contrib"
projects[imagecache][subdir] = "contrib"
 
projects[devel][subdir] = "contrib"
projects[jquery_update][subdir] = "contrib"
 
projects[google_analytics][subdir] = "contrib"
projects[flickr][subdir] = "contrib"
 
; Libraries
 
libraries[jquery_ui][download][type] = "get"
libraries[jquery_ui][download][url] = "http://jquery-ui.googlecode.com/files/jquery.ui-1.6.zip"
libraries[jquery_ui][directory_name] = "jquery.ui"
libraries[jquery_ui][destination] = "modules/contrib/jquery_ui"

if this were placed in your _empty_ site directory, example.com, it would download drupal core and all your specified modules. It could be executed via: drush make --prepare-install standard.make. the --prepare-install flag is optional, but will handle creating and permission-ing your settings.php file and your files/ directory.

So... How do I enable these modules, once i have them?

Here we have 3 diverging paths.

      1. You can visit /admin/modules and start checking boxes to hearts content.
      2. 'vanilla' drush - using drush en module_name1 module_name2 etc etc you can enable multiple modules at a time via the command-line (separated by a space), but this is also not ideal for a super large amount of modules.
      3. Installation profiles: and this is where it gets potentially tricky, but we'll keep it super simple for this example (see below)

Installation Profiles

Have you ever checked out the profiles/ directory in your Drupal install? If you haven't, now is the time... Inside it you'll see some interesting things.

You can override profile functions (shockingly enough) the same way you would handle theme or module overrides. If our profile is named 'standard' you would override default_profile_modules() with standard_profile_modules() and so on... these would be located in profiles/standard/standard.profile.

below, (truncated somewhat) are the Drupal default profile functions that enable modules and sets up our two default content types, 'page' and 'story'

function default_profile_modules() {
  return array('color', 'comment', 'help', 'menu', 'taxonomy', 'dblog');
}
 
function default_profile_tasks(&$task, $url) {
  $types = array(
    array(
      'type' => 'page',
      'name' => st('Page'),
      'module' => 'node',
      'description' => st("A <em>page</em>, similar in form to a <em>story</em>, is a simple method for creating and displaying information that rarely changes, such as an \"About us\" section of a website. By default, a <em>page</em> entry does not allow visitor comments and is not featured on the site's initial home page."),
      'custom' => TRUE,
      'modified' => TRUE,
      'locked' => FALSE,
      'help' => '',
      'min_word_count' => '',
    ),
    array(
      'type' => 'story',
      'name' => st('Story'),
      'module' => 'node',
      'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."),
      'custom' => TRUE,
      'modified' => TRUE,
      'locked' => FALSE,
      'help' => '',
      'min_word_count' => '',
    ),
  );
 
  foreach ($types as $type) {
    $type = (object) _node_type_set_defaults($type);
    node_type_save($type);
  }
 
  // Default page to not be promoted and have comments disabled.
  variable_set('node_options_page', array('status'));
  variable_set('comment_page', COMMENT_NODE_DISABLED);
 
  // Don't display date and author information for page nodes by default.
  $theme_settings = variable_get('theme_settings', array());
  $theme_settings['toggle_node_info_page'] = FALSE;
  variable_set('theme_settings', $theme_settings);
 
  // Update the menu router information.
  menu_rebuild();
}

Not too hard to figure out what's going on here. The point being, you can enable modules, create content types, even set up tasks for enabling other features or themes all in your installation profile. An invaluable resource for a developer who would rather spend their time developing over, well wasting time on repetition.

Go Go Gadget Research!

Speaking of invaluable resources, if you want to dig deeper, checkout DevelopmentSeed's OpenAtrium and ManagingNews for their installation profiles and makefiles. Spending time deconstructing these will help push you further ahead.

And, of course, every Drupal developer should go buy Pro Drupal Development. I can't say enough great things about it...

Post new comment

The content of this field is kept private and will not be shown publicly.
By submitting this form, you accept the Mollom privacy policy.

Joseph Smith

Joseph Smith

Joseph currently works full-time as a freelance developer on projects for twoHard.

In his past life, he was a touring musician and turned screws on/repaired Apple hardware.

Tags