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

In this case we set the array key to store_create_content_types, which is the<br />

callback function for this task. The type is set to normal, meaning this is a task<br />

that is run, and may return HTML.<br />

Then in our profile, we create the function store_create_content_types()<br />

as follows:<br />

function store_create_content_types(&$install_state) {<br />

$types = array(<br />

array(<br />

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

'name' => st('Page'),<br />

'base' => 'node_content',<br />

'description' => st("Use pages for your static content,<br />

such as an 'About us' page."),<br />

'custom' => 1,<br />

'modified' => 1,<br />

'locked' => 0,<br />

),<br />

array(<br />

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

'name' => st('Product'),<br />

'base' => 'node_content',<br />

'description' => st('Use products for items in the<br />

store.'),<br />

'custom' => 1,<br />

'modified' => 1,<br />

'locked' => 0,<br />

),<br />

);<br />

}<br />

foreach ($types as $type) {<br />

$type = node_type_set_defaults($type);<br />

node_type_save($type);<br />

node_add_body_field($type);<br />

}<br />

In this case the function has one variable passed, it being $install_state. This is<br />

a variable passed through the entire install process and each of the tasks. It contains<br />

the state and all relevant information that needs to be passed around the installer.<br />

The content of this function defines two content types. It also makes sure that all the<br />

default information is filled in, and saves the types creating two new content types.<br />

[ 350 ]

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

Saved successfully!

Ooh no, something went wrong!