Same name and namespace in other branches
- 4.7.x developer/examples/block_example.module \block_example_block()
- 5.x developer/examples/block_example.module \block_example_block()
Implementation of hook_block().
This hook both declares to Drupal what blocks are provided by the module, and generates the contents of the blocks themselves.
File
- developer/
examples/ block_example.module, line 31 - This is an example outlining how a module can be used to define a block to be displayed on the right or left side of each page.
Code
function block_example_block($op = 'list', $delta = 0) {
// The $op parameter determines what piece of information is being requested.
if ($op == 'list') {
// If $op is "list", we just need to return a list of block descriptions. This
// is used to provide a list of possible blocks to the administrator.
$blocks[0]['info'] = t('A simple text string');
$blocks[1]['info'] = t('An empty block');
return $blocks;
}
else {
if ($op == 'view') {
// If $op is "view", then we need to generate the block for display purposes.
// The $delta parameter tells us which block is being requested.
switch ($delta) {
case 0:
// The subject is displayed at the top of the block. Note that it should
// be passed through t() for translation.
$block['subject'] = t('Title of block #1');
// The content of the block is typically generated by calling a custom
// function.
$block['content'] = block_example_contents(1);
break;
case 1:
$block['subject'] = t('Title of block #2');
$block['content'] = block_example_contents(2);
break;
}
return $block;
}
}
}