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.

Chapter 4<br />

}<br />

return $query;<br />

/**<br />

* Implements hook_block_info().<br />

*/<br />

function single_blog_block_info() {<br />

$blocks = array();<br />

// The array key defines the $delta parameter used in all<br />

// other block hooks.<br />

$blocks['recent'] = array(<br />

// The name of the block on the blocks administration page.<br />

'info' => t('Recent blog posts'),<br />

);<br />

}<br />

return $blocks;<br />

/**<br />

* Implements hook_block_view().<br />

*<br />

* Third draft!<br />

*<br />

* @pararm $delta<br />

* The name of the requested block.<br />

*/<br />

function single_blog_block_view($delta = '') {<br />

// Create an empty block.<br />

$block = array(<br />

'subject' => '',<br />

'content' => '',<br />

);<br />

// Check which block is being requested.<br />

if ($delta == 'recent') {<br />

// Set the block title.<br />

$block['subject'] = t('Recent blog posts');<br />

// Check if the user can access content.<br />

if (user_access('access content')) {<br />

// Retrieve the most recent nodes.<br />

$result = single_blog_list(SINGLE_BLOG_LIST_COUNT);<br />

[ 111 ]

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

Saved successfully!

Ooh no, something went wrong!