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.

<strong>Drupal</strong>’s Theme Layer<br />

• #suffix: A string containing markup to be appended to the<br />

#children property.<br />

• #weight: A number used to sort child elements.<br />

• #sorted: A Boolean indicating if the child elements have already been<br />

sorted. Since sorting a render array is expensive, if you know the data is<br />

already sorted (for example, the data was sorted when retrieved from the<br />

database), you should set this property to TRUE.<br />

• #states: JavaScript state information.<br />

• #attached: An array of CSS, JavaScript, libraries, or other associated<br />

attachments related to the element. See drupal_process_attached()<br />

for more information.<br />

• #printed: A Boolean indicating if the element has already been rendered.<br />

hook_element_info<br />

The second place properties are defined is inside hook_element_info().<br />

Each #type of render element needs to be defined in an implementation of<br />

hook_element_info(). system_element_info() defines most of <strong>Drupal</strong> core's<br />

render elements, which include several useful elements such as the markup element,<br />

the link element, and all the form elements. The following is a short snippet from<br />

system_element_info():<br />

/**<br />

* Implements hook_element_info().<br />

*/<br />

function system_element_info() {<br />

// HTML markup.<br />

$types['markup'] = array(<br />

'#markup' => '',<br />

'#pre_render' => array('drupal_pre_render_markup'),<br />

);<br />

// A HTML link.<br />

$types['link'] = array(<br />

'#pre_render' => array('drupal_pre_render_link',<br />

'drupal_pre_render_markup'),<br />

);<br />

// A hidden form element.<br />

$types['hidden'] = array(<br />

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

'#process' => array('ajax_process_form'),<br />

'#theme' => 'hidden',<br />

);<br />

}<br />

return $types;<br />

[ 80 ]

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

Saved successfully!

Ooh no, something went wrong!