18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Installation Profiles<br />

There are some tasks which need to be run after a certain point in the process on<br />

every page load. An example of this is in the default install tasks. The installer<br />

initializes with a low-level <strong>Drupal</strong> bootstrap enabling very base level functionality.<br />

After the modules have been installed but before the site configuration part of the<br />

process, there is a point when the installer can do a full <strong>Drupal</strong> bootstrap with all the<br />

functionality of all the enabled modules. Once the installer reaches this point it runs<br />

a task on all subsequent page loads to perform a full <strong>Drupal</strong> bootstrap. The definition<br />

for this task looks like the following:<br />

$tasks = array(<br />

...<br />

'install_bootstrap_full' => array(<br />

'run' => INSTALL_TASK_RUN_IF_REACHED,<br />

),<br />

...<br />

);<br />

By setting run to INSTALL_TASK_RUN_IF_REACHED, the function install_bootstrap_<br />

full() is run on every page load after it is encountered in the install tasks.<br />

Altering tasks<br />

The installer provides a method to alter tasks in the installer. Where<br />

hook_install_tasks() provides a method to add tasks at the end of the install<br />

process, hook_install_tasks_alter() provides access to all the tasks in the<br />

installer (including the default tasks provided by the installer). This allows a profile<br />

to insert tasks earlier in the install process or alter the default tasks.<br />

Tasks performed before the install_bootstrap_full() task, which<br />

is before the modules are installed, only have access to a very base level of<br />

<strong>Drupal</strong> configuration, with access to the system module, user module, the<br />

PHP settings, and a site's settings.php file.<br />

Let's look at an example of altering tasks before the modules are installed; only the<br />

base level system is available, which means your installation profile is not yet able to<br />

call hook_form_alter or hook_form_FORM_ID_alter. In this case we want to alter<br />

the step where the database is set up to add some additional instructions.<br />

/**<br />

* Implements hook_install_tasks_alter().<br />

*/<br />

function store_install_tasks_alter(&$tasks, &$install_state) {<br />

$tasks['install_settings_form']['function'] = 'store_database_<br />

settings_form';<br />

}<br />

[ 354 ]

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

Saved successfully!

Ooh no, something went wrong!