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 />

• display_name: A human readable name to display for this task. This is used<br />

in the user interface to inform a user as to the step they are on.<br />

• display: tells the installer whether or not to display the task. This is used to<br />

provide fine-grained control over the display of the task in the installer. It is<br />

useful for tasks that may display only under certain conditions. The value is a<br />

Boolean and the default value is whether or not the "display_name" key is set.<br />

• type: Specifies the type of task to be run. There are three types of tasks the<br />

installer can execute. The normal type of task will execute a callback function<br />

and optionally return some html. The form type brings up a form using the<br />

Form API. The batch type will return a Batch API definition.<br />

• run: Tells the installer when to run the task. The default setting is<br />

INSTALL_TASK_RUN_IF_NOT_COMPLETED, which tells the installer to run<br />

the task once in the install process when reached in the list of install tasks.<br />

Alternately, INSTALL_TASK_RUN_IF_REACHED tells the installer to run<br />

the task on every page load if the task is reached in the list of tasks and<br />

INSTALL_TASK_SKIP tells the installer to skip the task.<br />

• function: An optional parameter to set a callback function other than the<br />

key name. This is useful if you want to call the same callback function on<br />

more than one step.<br />

Creating a task<br />

Let's create two tasks for the store profile. The tasks will create two content types<br />

and fill in default settings for our site-wide contact form.<br />

We start by defining the task to create the two content types. This will be done in<br />

store_install_tasks(), the profiles implementation of hook_install_tasks()<br />

which goes in store.profile:<br />

/**<br />

* Implements hook_install_tasks().<br />

*/<br />

function store_install_tasks() {<br />

$tasks = array();<br />

$tasks['store_create_content_types'] = array(<br />

'type' => 'normal',<br />

);<br />

return $tasks;<br />

}<br />

[ 349 ]

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

Saved successfully!

Ooh no, something went wrong!