Drupal-Module programmieren

Vorgehensweise

  1. shortname (lowercase)
  2. sites/all/modules/modulename
  3. modulename.module:
    <?php
    // $Id$
  4. omit the closing ?>
  5. Hooks: {modulename}_{hook}
  6. modulename.info:
    ; $Id$
    name = Module name
    description = A description of what your module does.
    core = 6.x
  7. description ohne linebreaks, max. 255 Zeichen, keine Sonderzeichen (aber HTML-Entitäten), keine Anführungszeichen
  8. optional: dependencies[] = anderes_modul
  9. hook_help:
    /**
    * Display help and module information
    * @param path which path of the site we're displaying help
    * @param arg array that holds the current path as would be returned from arg() function
    * @return help text for the path
    */
    function onthisdate_help($path, $arg) {
      $output = '';  //declare your output variable
      switch ($path) {
        case "admin/help#onthisdate":
          $output = '<p>'.  t("Displays links to nodes created on this date") .'</p>';
          break;
      }
      return $output;
    } // function onthisdate_help
  10. mehr Info: http://api.drupal.org/api/function/hook_help
  11. hook_perm:
    /**
    * Valid permissions for this module
    * @return array An array of valid permissions for the onthisdate module
    */
    function onthisdate_perm() {
      return array('access newmodule', 'create newmodule', 'administer newmodule'); // ein Wert genuegt
    } // function onthisdate_perm()
  12. hook_block:
    /**
    * Implementation of hook_block
    * @param string $op one of "list", "view", "save" and "configure"
    * @param integer $delta code to identify the block
    * @param array $edit only for "save" operation
    **/
    function onthisdate_block($op = 'list', $delta = 0, $edit = array()) {
    if ($op == "list") {
        // Generate listing of blocks from this module, for the admin/block page
        $block = array();
        $block[0]["info"] = t('On This Date'); // "info", "cache", "weight", "status"
        return $block;
      }
    } // function onthisdate_block
  13. hook_block erweitern:
      else if ($op == 'view') {
        // Generate our block content
        // Get today's date
        $today = getdate();
        // calculate midnight one week ago
        $start_time = mktime(0, 0, 0,
           $today['mon'], ($today['mday'] - 7), $today['year']);
        // we want items that occur only on the day in question, so 
        // calculate 1 day
        $end_time = $start_time + 86400;
        // 60 * 60 * 24 = 86400 seconds in a day
        // set up the block
        $block = array();
        $block['subject'] = 'On This Date';
        $block['content'] = $block_content;
        return $block;
      }
  14. admin_funktion
  15. hook_menu (siehe auch http://api.drupal.org/api/function/hook_menu/6)
  16. onthisdate_admin_validate (mit Suffix _validate)