Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?php
  2. // $Id$
  3.  
  4. //Valid permissions for this module
  5. function artoteka_perm() {
  6.   return array('access artoteka','administer artoteka');
  7. } // function artoteka_perm()
  8.  
  9. // Add menu item linked to modul adminstration (settings).
  10. function artoteka_menu() {
  11.   $items = array();
  12.   $items['admin/settings/artoteka'] = array(
  13.     'title' => 'Artoteka module settings',
  14.     'description' => 'Set values',
  15.     'page callback' => 'drupal_get_form',
  16.     'page arguments' => array('artoteka_admin'),
  17.     'access arguments' => array('access administration pages'),
  18.     'type' => MENU_NORMAL_ITEM,
  19.    );
  20.   return $items;
  21. } // function artoteka_menu()
  22.  
  23. function artoteka_admin() {
  24.   $form = array();
  25.  
  26.   $form['value1'] = array(
  27.     '#type' => 'textfield',
  28.     '#title' => t('Number value'),
  29.     '#default_value' => variable_get('value1', 1),
  30.     '#size' => 2,
  31.     '#maxlength' => 2,
  32.     '#description' => t("Set number value."),
  33.     '#required' => TRUE,
  34.   );
  35.  
  36.    $form['value2'] = array(
  37.     '#type' => 'textfield',
  38.     '#title' => t('Number value'),
  39.     '#default_value' => variable_get('value2', 1),
  40.     '#size' => 2,
  41.     '#maxlength' => 2,
  42.     '#description' => t("Set number value."),
  43.     '#required' => TRUE,
  44.   );
  45.  
  46.    $form['value3'] = array(
  47.     '#type' => 'textfield',
  48.     '#title' => t('Number value'),
  49.     '#default_value' => variable_get('value3', 1),
  50.     '#size' => 2,
  51.     '#maxlength' => 2,
  52.     '#description' => t("Set number value."),
  53.     '#required' => TRUE,
  54.   );
  55.  
  56. return system_settings_form($form);
  57.  
  58. }
  59.  
  60. /**
  61. * Implementation of hook_block().
  62. * @param string $op one of "list", "view", "save" and "configure"
  63. * @param integer $delta code to identify the block
  64. * @param array $edit only for "save" operation
  65. */
  66. function artoteka_block($op='list', $delta=0) {
  67. // Set up artoteka_block
  68. $block = array();
  69.  
  70.     switch ($op) {
  71.  
  72.       case 'list':
  73.         // Generate listing of blocks from this module, for the admin/block page
  74.         $block[0]["info"] = t('Artoteka');
  75.       break;
  76.      
  77.       case 'view':
  78.     // Generate our block content,
  79.       // variableS that will be returned for display
  80.     // Get stored values.
  81.     $value1 = variable_get('value1',1);
  82.     $value2 = variable_get('value2',1);
  83.     $value3 = variable_get('value3',1);
  84.       $block_content = t('Global value "1" is ').$value1."<br />";
  85.     $block_content .= t('Global value "2" is ').$value2."<br />";
  86.     $block_content .= t('Global value "3" is ').$value3."<br />";
  87.  
  88.     $block['subject'] = 'Variables inside block';
  89.      
  90.       // check to see if there was any
  91.       // content before returning the block view
  92.         if ($block_content == '') {  
  93.            // no content
  94.            $block['content'] = 'Set values';
  95.         }
  96.         else {
  97.           // set up the block
  98.           $block['content'] = $block_content;
  99.         }
  100.       break;
  101.    
  102.     }// end switch
  103.  
  104.   return $block;
  105. }  
  106. // end artoteka_block
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement