18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Installation Profiles<br />

The install task system<br />

The <strong>Drupal</strong> installer is task based. Tasks consist of steps to collect information and<br />

act on it. For example, three of the core tasks are to collect the database configuration<br />

details, write the database configuration to the settings.php file, and install the<br />

modules. <strong>Drupal</strong> core provides a set of default tasks for the installer to run that<br />

an installation profile can add to or alter. The two hooks that provide access to<br />

the install tasks are:<br />

• hook_install_tasks(): This allows the profile to add tasks at the end of the<br />

default tasks<br />

• hook_install_tasks_alter(): This allows the profile to alter all the tasks<br />

including those provided as defaults by the installer<br />

For the first step of the installer, an installation profile is selected. This<br />

step cannot be altered by an installation profile.<br />

Choosing an install task or using hook_install<br />

Since profiles operate as a module, they can have a .install file containing a<br />

hook_install() which will be called when the profile is installed. This leaves<br />

two choices of where to perform configuration tasks.<br />

There are two main differences between these two types of tasks:<br />

• The profile hook_install() is run before custom install tasks and the site<br />

configuration form.<br />

• Tasks in the installer can have forms, utilize the Batch API, and more.<br />

hook_install() can only run as a callback in a single page load.<br />

For complete documentation regarding hook_install() visit the API<br />

documentation at http://api.drupal.org/api/function/hook_<br />

install/7.<br />

Anatomy of an install task<br />

There are five properties to describe each task step to the installer.<br />

hook_install_tasks() describes each step to the installer as a keyed array. The key<br />

is a unique name to a callback function that executes the task. The properties of each<br />

item describing the task are as follows:<br />

[ 348 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!