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.

Theming a <strong>Module</strong><br />

// Create links for each blog entry.<br />

$items = array();<br />

foreach ($result as $node) {<br />

$items[] = array(<br />

'data' => array(<br />

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

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

),<br />

'class' => array('node-' . $node->nid),<br />

);<br />

}<br />

}<br />

}<br />

if (!empty($items)) {<br />

// Theme the list of blog entries.<br />

$block['content']['list'] = array(<br />

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

'#items' => $items,<br />

'#pre_render' =><br />

array('single_blog_item_list_child_render'),<br />

);<br />

// Add a link to the full list of blog entries.<br />

$block['content']['more'] = array(<br />

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

'#url' => 'blog',<br />

'#title' => t('Read the latest blog entries.'),<br />

);<br />

// Add a CSS file to style the block.<br />

$block['content']['#attached']['css'][] =<br />

drupal_get_path('module', 'single_blog') . '/single-blog.css';<br />

}<br />

}<br />

return $block;<br />

/**<br />

* Render the child elements of theme_item_list() before its data is<br />

themed.<br />

*/<br />

function single_blog_item_list_child_render($elements) {<br />

foreach (array_keys($elements['#items']) AS $key) {<br />

// Take the renderable array that we set in<br />

[ 112 ]

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

Saved successfully!

Ooh no, something went wrong!