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.

Chapter 4<br />

}<br />

// single_blog_block_view() and render it into the string<br />

// that theme_item_list() expects.<br />

if (is_array($elements['#items'][$key]['data'])) {<br />

$elements['#items'][$key]['data'] =<br />

drupal_render($elements['#items'][$key]['data']);<br />

}<br />

}<br />

return $elements;<br />

/**<br />

* Implements hook_theme().<br />

*/<br />

function single_blog_theme($existing, $type, $theme, $path) {<br />

return array(<br />

'single_blog_block_item' => array(<br />

'variables' => array(<br />

'node' => NULL,<br />

),<br />

'template' => 'single-blog-block-item',<br />

),<br />

);<br />

}<br />

/**<br />

* Preprocesses single blog block item variables.<br />

*/<br />

function template_preprocess_single_blog_block_item(&$variables) {<br />

$node = $variables['node'];<br />

// Create a renderable array for the title.<br />

$variables['title'] = array(<br />

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

'#title' => $node->title,<br />

'#href' => 'node/' . $node->nid,<br />

);<br />

// Format the creation date of the node.<br />

$variables['created'] = $node->created;<br />

$variables['date'] = format_date($node->created, 'custom',<br />

SINGLE_BLOG_DATE_FORMAT);<br />

[ 113 ]

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

Saved successfully!

Ooh no, something went wrong!