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

Text filters<br />

Text filters, known as input formats in previous versions of <strong>Drupal</strong>, are created<br />

and configured by the installation profile. In order for a site to have text filters<br />

that users can choose from, the installation profile must set up the filter first. The<br />

simplest method for setting them up is in the hook_install() function inside the<br />

profile's .install file. Continuing our example, the following code at the top of<br />

store_install() would add Filtered HTML and Full HTML text filters, with the<br />

filtered one set as the default:<br />

// Add text formats.<br />

$filtered_html_format = array(<br />

'format' => 'filtered_html',<br />

'name' => 'Filtered HTML',<br />

'weight' => 0,<br />

'filters' => array(<br />

// URL filter.<br />

'filter_url' => array(<br />

'weight' => 0,<br />

'status' => 1,<br />

),<br />

// HTML filter.<br />

'filter_html' => array(<br />

'weight' => 1,<br />

'status' => 1,<br />

),<br />

// Line break filter.<br />

'filter_autop' => array(<br />

'weight' => 2,<br />

'status' => 1,<br />

),<br />

// HTML corrector filter.<br />

'filter_htmlcorrector' => array(<br />

'weight' => 10,<br />

'status' => 1,<br />

),<br />

),<br />

);<br />

$filtered_html_format = (object) $filtered_html_format;<br />

filter_format_save($filtered_html_format);<br />

$full_html_format = array(<br />

'format' => 'full_html',<br />

'name' => 'Full HTML',<br />

'weight' => 1,<br />

'filters' => array(<br />

[ 358 ]

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

Saved successfully!

Ooh no, something went wrong!