Speed Up Your Drupal Development Using Installations and Distributions

Setting the Administration Theme

Basically, what I now have is a copy of the minimal installation profile with some additional modules and themes. The first thing I want to do next is use the Seven theme for the administration pages of the site, as it would be if I'd used the standard installation profile. To do this, I first need to enable Seven and then set some variables to set it as the administration theme. I can reference the .install file from the standard installation profile to find out how to do this. To do so, I add the following code into the linuxjournal_install() function in linuxjournal.install:


// Enable the administration theme.
$admin_theme = 'seven';
db_update('system')
  ->fields(array('status' => 1))
  ->condition('type', 'theme')
  ->condition('name', $admin_theme)
  ->execute();
variable_set('admin_theme', $admin_theme);
variable_set('node_admin_theme', '1');

Creating Content Types

The standard installation profile also creates two default content types: basic pages and articles. I'm going to re-use most of this code to create the basic page content type for my profile:


// Add a 'Basic page' content type.
$types = array(
  array(
    'type' => 'page',
    'name' => st('Basic page'),
    'base' => 'node_content',
    'description' => st("Use <em>basic pages</em> for 
 ↪your static content, such as an 'About us' page."),
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
  );
);

foreach ($types as $type) {
  $type = node_type_set_defaults($type);
  node_type_save($type);
  node_add_body_field($type);
}

// Default 'Basic page' to not be promoted and don't 
// display author information.
variable_set('node_options_page', array('status'));
variable_set('node_submitted_page', FALSE);

To create additional content types, I can keep adding new items into the $types array, and they will be processed within the foreach() loop.

Adding Text Formats and a WYSIWYG Editor

When you use the standard installation profile, several different text formats are created. Currently, I have only plain text and PHP code (because the PHP module is now also a dependency for my profile). I also want the additional text formats, so I'll copy that section of code from the standard.install file and paste in into the linuxjournal_install() function:


// Add text formats.
$text_formats['filtered_html'] = array(
  'format' => 'filtered_html',
  'name' => 'Filtered HTML',
  'weight' => 0,
  'filters' => array(
    // URL filter.
    'filter_url' => array(
      'weight' => 0,
      'status' => 1,
    ),
    // HTML filter.
    'filter_html' => array(
      'weight' => 1,
      'status' => 1,
    ),
      // Line break filter.
    'filter_autop' => array(
      'weight' => 2,
      'status' => 1,
    ),
    // HTML corrector filter.
    'filter_htmlcorrector' => array(
      'weight' => 10,
      'status' => 1,
    ),
  ),
);
$text_formats['full_html'] = array(
  'format' => 'full_html',
  'name' => 'Full HTML',
  'weight' => 1,
  'filters' => array(
    // URL filter.
    'filter_url' => array(
      'weight' => 0,
      'status' => 1,
    ),
      // Line break filter.
    'filter_autop' => array(
      'weight' => 1,
      'status' => 1,
    ),
    // HTML corrector filter.
    'filter_htmlcorrector' => array(
      'weight' => 10,
      'status' => 1,
    ),
  ),
);
$text_formats['raw_html'] = array(
  'format' => 'raw_html',
  'name' => 'Raw HTML',
  'weight' => 2,
);
foreach ($text_formats as $text_format) {
  $text_format = (object) $text_format;
  filter_format_save($text_format);
}

I've amended the format slightly by creating an array called $text_formats, and then using a foreach loop to save each one as opposed to doing them separately as it is done in standard.install. I also usually create a Raw HTML format that allows all HTML tags and doesn't have any filters applied to it, so I've added it here as an additional format to be created automatically.

Adding TinyMCE and Enabling It for Certain Text Formats

I also download and install the WYSIWYG module and the TinyMCE editor for each site. Rather than having to download and enable the WYSIWYG module, download and extract the TinyMCE library and configure the editor, I can add it into my profile to have it done automatically. First, I need to add the WYSIWYG (http://drupal.org/project/wysiwyg) and Libraries API (http://drupal.org/project/libraries) modules and add them into dependencies to have them enabled by default.

In linuxjournal.make:


projects[wysiwyg][type] = module
projects[wysiwyg][subdir] = contrib
projects[wysiwyg][version] = 2.1
projects[wysiwyg][download][type] = git
projects[wysiwyg][download][url] = 
 ↪http://git.drupal.org/project/wysiwyg.git
projects[wysiwyg][download][branch] = 7.x-2.x

projects[libraries][type] = module
projects[libraries][subdir] = contrib
projects[libraries][version] = 2.0
projects[libraries][download][type] = git
projects[libraries][download][url] = 
 ↪http://git.drupal.org/project/libraries.git
projects[libraries][download][branch] = 7.x-2.x

libraries[tinymce][type] = library
libraries[tinymce][download][type] = get
libraries[tinymce][download][url] = 
 ↪http://github.com/downloads/tinymce/tinymce/tinymce_3.5.6.zip

In linuxjournal.info:


dependencies[] = libraries
dependencies[] = wysiwyg

TinyMCE will be downloaded and extracted into the profiles/linuxjournal/profiles directory and will be accessible by the WYSIWYG module once Libraries API is enabled. However, now that it has been downloaded, I need to assign it to one of my text formats before it can be used. The format I'm going to assign it to is Filtered HTML, and I can do that by adding a record into the wysiwyg table in the database. I've also added an array of default settings that I've used on another site, and I've added this into the drupal_write_record() function:


// Add the TinyMCE editor to the Filtered HTML text format.
$tinymce_settings = array(
  'default' => 1,
  'user_choose' => 0,
  'show_toggle' => 0,
  'theme' => 'advanced',
  'language' => 'en',
  'buttons' => array(
    'default' => array(
      'bold' => 1,
      'italic' => 1,
      'strikethrough' => 1,
      'justifyleft' => 1,
      'justifycenter' => 1,
      'justifyright' => 1,
      'justifyfull' => 1,
      'bulllist' => 1,
      'numlist' => 1,
      'link' => 1,
      'unlink' => 1,
      'anchor' => 1,
      'image' => 1,
      'formatselect' => 1,
      'sup' => 1,
      'sub' => 1,
      'blockquote' => 1,
      'code' => 1,
      'hr' => 1,
      'removeformat' => 1,
      'charmap' => 1,
    ),
  ),
  'toolbar_loc' => 'top',
  'toolbar_align' => 'left',
  'path_loc' => 'bottom',
  'resizing' => 1,
  'verify_html' => 1,
  'preformatted' => 0,
  'convert_fonts_to_spans' => 1,
  'remove_linebreaks' => 1,
  'apply_source_formatting' => 0,
  'paste_auto_cleanup_on_paste' => 1,
  'block_formats' => 'p,address,pre,h2,h3,h4,h5,h6,div',
  'css_setting' => 'theme',
  'css_path' => '',
  'css_classes' => '',
);

// Create the record.
$record = array(
  'format' => 'filtered_html',
  'editor' => 'tinymce',
  'settings' => $tinymce_settings,
);

// Save the record to the database.
drupal_write_record('wysiwyg', $record);

It's worth noting here that the $tinymce_settings variable needs to be a standard PHP array as it will be serialized automatically when it is written into the database table. When I first tried this, I tried importing a pre-serialized array into the database, which subsequently generated errors when trying to view the WYSIWYG admin settings form.

______________________

Oliver Davies is an Application Developer at Nomensa, specializing in Drupal and PHP development. Outside work, Oliver is a keen contributor to the Drupal community—attending local user groups and maintaining several of his own contributed modules.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

info

Anonymous's picture

Thanks for this article. It's just what I was searching for. I am always interested in this subject. Will bookmark it.
indiaseowordpressdesigns

thanks for the information,

dherach's picture

thanks for the information, this article really helped me in performing their duties. this my blog resep ayam

Reply to comment | Linux Journal

cell port thailand's picture

cellport clinic bangkok

Feel free to visit my weblog ... cell port thailand

Reply to comment | Linux Journal

d&#039;leedon's picture

Potong Pasir MRT at the doorstep, residents can easily access almost to any destination
through.d'leedon

thanks for the information,

dherach's picture

thanks for the information, this article really helped me in performing their duties. this my blog resep ayam

The difference between install profiles and distros

marcvangend's picture

Thanks for the article. A quick note about the title: I think you meant to say "Installation Profiles" instead of "Installations".

Your article is mainly about creating installation profiles and not so much about distributions. That's okay, because installation profiles are great and they can indeed speed up your development process.

IMHO it's too easy to say that "distributions are install profiles on drupal.org" and be done with it. The big difference is that if you use a distribution, you're no longer the maintainer of that code. That has some advantages like the availability of support and updates. The disadvantage is, that if you want to change the way a distribution works, you cannot simply go in and change the code. If you did that, it would get much harder to get support and install updates. In my experience, a distribution can dramatically speed up your development process if it is exactly (or very close to) what you need. If you are planning to make a lot of changes, building on a distribution may even slow down your development process. This is especially true for distributions with lots of features and styling, such as Open Atrium.

Features / Exportables

btopro's picture

Nice article, Features, Profiler and Profiler Builder modules would all help in making a more complete export and install package (and faster) :)

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState