Making a block example done live at WesternMassDrupalCamp 2011
The most fun lesson learned– passing in a pure integer to the $block['content'] in the implementation of hook_block_view causes an unsupported operand error so deep in the block rendering system the stack trace doesn't even know where it came from.
<?php
/**
* Implements hook_block_info().
*/
function dgd7glue_block_info() {
$blocks = array();
$blocks['twoplustwo'] = array(
'info' => t('Two plus two.'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function dgd7glue_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'twoplustwo':
$block['subject'] = t('Two plus two equals');
$result = 2 + 2;
$content = t('This is a string of the number ') . $result;
$build = array();
$build['main_content'] = array(
'#markup' => $content,
'#weight' => 15,
);
$build['morehere'] = array(
'#type' => 'link',
'#title' => t('Exit block region demonstration'),
'#href' => 'admin/structure/block',
'#options' => array('attributes' => array('class' => array('block-demo-backlink', 'overlay-restore'))),
'#weight' => -10,
);
$block['content'] = $build;
break;
}
return $block;
}
?>
Comments
Post new comment