Drupal hook: hook_block

Printer-friendly versionSend to a DeveloperPDF version

Blocks are the one of the basic and most fascinating features of Drupal. With block you can display information in the form of block by saving and utilizing the screen area. Here is an example of implementation of hook_block

<?php
/**
* Implementation of hook_block
*
* @param $op
* @param $delta
* @param $edit
* @return $block
* @author Drupal Developer
*/
function browse_info_block($op = 'list', $delta = 0, $edit = array()) {
    switch (
$op) {
        case
'list':
           
$blocks[1] = array(
       
'info' => t("Browse information by category"),
             
'status' => 1,
             
'region' => 'content',
             
'weight' => 0,
            );
           
            return
$blocks;
        case
'configure':
           
$am__vocabulary = _get_vocabulary();
           
$am__imagecache = _get_imagecache();
           
           
$form['browse_vocabulary'] = array(
             
'#type' => 'select',
             
'#title' => t("Vocabulary"),
             
'#options' => $am__vocabulary,
             
'#default_value' => variable_get('browse_vocabulary_id', ''),
            );
           
$form['imagecahce'] = array(
             
'#type' => 'select',
             
'#title' => t("Image size"),
             
'#options' => $am__imagecache,
             
'#default_value' => variable_get('imagecache_size', ''),
            );
           
$form['image_size'] = array(
             
'#type' => 'textfield',
             
'#title' => t("Image size"),
             
'#size' => 30,
             
'#description' => t("Provide image size in WXH format.
                This value will be ignored if a size already selected from above ImageCache presets."
),
             
'#default_value' => variable_get('image_size', ''),
            );
            return
$form;
        case
'save':
            switch (
$delta) {
                case
1:
                   
variable_set('browse_vocabulary_id', $edit['browse_vocabulary']);
                   
variable_set('imagecache_size', $edit['imagecahce']);
                   
variable_set('image_size', $edit['image_size']);
                    break;
            }
            break;   
        case
'view':
            switch (
$delta) {
                case
1:
                   
$block = array('subject' => t("Browse information by category"), 'content' => get_category_tree());
                    break;
            }
            return
$block;
    }
}
//This is an example from one my live websites
?>

Syndicate content

Recent comments

toolbar powered by www.mit3xxx.de