Posted By

budda on 05/27/09


Tagged

drupal block


Versions (?)

hook_block


 / Published in: PHP
 

URL: http://api.lullabot.com/hook_block/6

  1. function hook_block($op = 'list', $delta = 0, $edit = array()) {
  2. if ($op == 'list') {
  3. $blocks[0] = array('info' => t('Mymodule block #1 shows ...'),
  4. 'weight' => 0, 'status' => 1, 'region' => 'left');
  5. // BLOCK_CACHE_PER_ROLE will be assumed for block 0.
  6.  
  7. $blocks[1] = array('info' => t('Mymodule block #2 describes ...'),
  8. 'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE);
  9.  
  10. return $blocks;
  11. }
  12. else if ($op == 'configure' && $delta == 0) {
  13. $form['items'] = array(
  14. '#type' => 'select',
  15. '#title' => t('Number of items'),
  16. '#default_value' => variable_get('mymodule_block_items', 0),
  17. '#options' => array('1', '2', '3'),
  18. );
  19. return $form;
  20. }
  21. else if ($op == 'save' && $delta == 0) {
  22. variable_set('mymodule_block_items', $edit['items']);
  23. }
  24. else if ($op == 'view') {
  25. switch($delta) {
  26. case 0:
  27. $block = array('subject' => t('Title of block #1'),
  28. 'content' => mymodule_display_block_1());
  29. break;
  30. case 1:
  31. $block = array('subject' => t('Title of block #2'),
  32. 'content' => mymodule_display_block_2());
  33. break;
  34. }
  35. return $block;
  36. }
  37. }

Report this snippet  

You need to login to post a comment.