Drupal-Module programmieren
Vorgehensweise
- shortname (lowercase)
- sites/all/modules/modulename
- modulename.module:
<?php // $Id$
- omit the closing
?>
- Hooks: {modulename}_{hook}
- modulename.info:
; $Id$ name = Module name description = A description of what your module does. core = 6.x
- description ohne linebreaks, max. 255 Zeichen, keine Sonderzeichen (aber HTML-Entitäten), keine Anführungszeichen
- optional: dependencies[] = anderes_modul
- 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
- mehr Info: http://api.drupal.org/api/function/hook_help
- 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()
- 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
- 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; }
- admin_funktion
- hook_menu (siehe auch http://api.drupal.org/api/function/hook_menu/6)
- onthisdate_admin_validate (mit Suffix _validate)
|