Posted By

wza on 09/10/10


Tagged

textmate template module drupal admin block


Versions (?)

create drupal block


 / Published in: Other
 

  1. <?php
  2. // $Id: hello module Exp $
  3.  
  4. // keep the module name consistent throughout
  5. global $moduleName;
  6. $moduleName = "hello";
  7.  
  8. // call menu hook to create an administration menu to create content for your hello module
  9. function hello_menu() {
  10. global $moduleName;
  11. $items = array();
  12. $items['admin/settings/'.$moduleName] = array(
  13. 'title' => ucfirst($moduleName),
  14. 'description' => 'Set '.$moduleName.' code',
  15. 'page callback' => 'drupal_get_form',
  16. 'page arguments' => array($moduleName.'_admin'),
  17. 'access arguments' => array('access administration pages'),
  18. 'type' => MENU_NORMAL_ITEM,
  19. );
  20. return $items;
  21. }
  22.  
  23. // call admin hook to let you administrate the content of this hello block
  24. function hello_admin() {
  25. global $moduleName;
  26. $form = array();
  27. $form[$moduleName.'_show_title'] = array(
  28. '#type' => 'checkbox',
  29. '#title' => t('Show title'),
  30. '#default_value' => variable_get($moduleName.'_show_title', '1'),
  31. '#required' => TRUE,
  32. );
  33. $form[$moduleName.'_number'] = array(
  34. '#type' => 'textfield',
  35. '#title' => t('How many blocks'),
  36. '#default_value' => variable_get($moduleName.'_number', '1'),
  37. '#maxlength' => 3,
  38. '#required' => TRUE,
  39. );
  40. $n = (int)variable_get($moduleName.'_number',1);
  41. for( $i=1;$i<$n+1;$i++ ) {
  42. ($i<2) ? $setreq = TRUE : $setreq = FALSE;
  43. $form[$moduleName.'_'.$i] = array(
  44. '#type' => 'textarea',
  45. '#title' => t(ucfirst($moduleName).' Block '.($i)),
  46. '#default_value' => variable_get($moduleName.'_'.$i, ''),
  47. '#maxlength' => 800,
  48. '#required' => $setreq,
  49. );
  50. }
  51. return system_settings_form($form);
  52. }
  53.  
  54. // call block hook and show in Drupal block the you assign
  55. function hello_block($op = 'list', $delta = 0) {
  56. global $moduleName;
  57. $block = array();
  58. if($op == 'list') {
  59. for($i=1;$i<variable_get($moduleName.'_number', '1')+1;$i++) {
  60. $block[$i]["info"] = t(ucfirst($moduleName).($i));
  61. }
  62. } else if ($op == 'view') {
  63. if (variable_get($moduleName.'_show_title', '1')==true)
  64. $block['subject'] = ucfirst($moduleName);
  65. $block['content'] = variable_get($moduleName.'_'.$delta, '');
  66. }
  67. return $block;
  68. }

Report this snippet  

You need to login to post a comment.