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.

Building an Admin Interface<br />

A shortcut for system settings<br />

The need to save configuration settings into persistent variables through a standard<br />

form is pretty common. Thankfully, once again <strong>Drupal</strong> has provided us with some<br />

magic to simplify this task. That magic is the system_settings_form() function.<br />

When you pass a standard Form API form array through this function and return<br />

the results, you get several benefits. Take a look at the following modified version<br />

of user_warn_form():<br />

/**<br />

* Form builder; Build the User Warn settings form.<br />

*/<br />

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

// Text field for the e-mail subject.<br />

$form['user_warn_e-mail_subject'] = array(<br />

'#type' => 'textfield',<br />

'#default_value' => 'Administrative Warning',<br />

'#title' => t('Warning e-mail subject'),<br />

'#size' => 40,<br />

'#maxlength' => 120,<br />

'#required' => TRUE,<br />

'#description' => t(<br />

'The subject of the e-mail which will be sent to users.'),<br />

);<br />

// Textarea for the body of the e-mail.<br />

$form['user_warn_e-mail_text'] = array(<br />

'#type' => 'textarea',<br />

'#rows' => 10,<br />

'#columns' => 40,<br />

'#default_value' => USER_WARN_MAIL_TEXT,<br />

'#title' => t('Warning e-mail text'),<br />

'#required' => TRUE,<br />

'#description' => t(<br />

'The text of the e-mail which will be sent to users.'),<br />

);<br />

// Checkbox to indicate whether admin should be sent a Bcc<br />

// on e-mails.<br />

$form['user_warn_bcc'] = array(<br />

'#type' => 'checkbox',<br />

'#default_value' => FALSE,<br />

'#title' => t('BCC admin on all e-mails'),<br />

[ 138 ]

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

Saved successfully!

Ooh no, something went wrong!