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.

Chapter 12<br />

Here, the task that sets up the database is altered, telling it to call a different function<br />

using the function key for the task.<br />

function store_database_settings_form($form, &$form_state, &$install_<br />

state) {<br />

// Retrieve the default form.<br />

$default_form = install_settings_form($form, &$form_state,<br />

&$install_state);<br />

$default_form['basic_options']['database']['#description'] .= st('<br />

If you choose use SQLite please provide an absolute path outside of<br />

the webroot directory.');<br />

return $default_form;<br />

}<br />

In this task callback function, we retrieve the default form provided by <strong>Drupal</strong>,<br />

alter it, and use that form. Since we are using a different form callback, we need to<br />

provide _validate and _submit handlers to process the information submitted in<br />

the form. The following two functions wrap the _validate and _submit functions<br />

used for install_settings_form():<br />

/**<br />

* Form API validate for store_database_settings_form form.<br />

*/<br />

function store_database_settings_form_validate($form, &$form_state) {<br />

install_settings_form_validate($form, &$form_state);<br />

}<br />

/**<br />

* Form API submit for store_database_settings_form form.<br />

*/<br />

function store_database_settings_form_submit($form, &$form_state) {<br />

install_settings_form_submit($form, &$form_state);<br />

}<br />

Configuring blocks<br />

Out of the box, <strong>Drupal</strong> does not have any blocks configured to be displayed.<br />

An installation profile will need to enable and configure any blocks it wants<br />

displayed. In this case we will use hook_install() in a store.install file as<br />

part of our install. When the modules for the profile are installed, the function<br />

store_install() will run, configuring the blocks. The following is a basic<br />

store_install() function enabling three blocks in the Bartik theme:<br />

function store_install() {<br />

// Enable some standard blocks.<br />

$values = array(<br />

array(<br />

[ 355 ]

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

Saved successfully!

Ooh no, something went wrong!