Drupal Notes 1: module hook_block(), hook_help(), check_plain(), check_url(), watchdog(), t(), l(), placeholders(!,%,@)

Create:
moduleName.info & moduleName.info, save them in sites, all, modules

.info example content:
;$Id$ // This will be substituted by Drupal CVS
name = “ModuleNameHere”
description = “Displays items blah blah blah”
core = 6.x
php = 5.1

.module beginnings…:
// $Id$ // This will be substituted by Drupal CVS
/**
* @file
// This denotes that this comment refers to this whole file
* Description Here Of Module…
* @see http://www.goodreads.com // Drupal doc is generated by doxygen, this links to a ref
*/

/**
* Implementation of hook_block()
*/

function moduleName_block($op=’list’, $delta=0, $edit=array()){
switch($op){
case ‘list’:
$blocks[0][‘info’] = t(‘Module Info Title’);
return $blocks;
case ‘view’:
$url = ‘http://www.moduleXML.com/review/list_rss/’;
$blocks[‘subject’] = t(‘Module Subject’);
$blocks[‘content’] = “Module Content Dynamic or Static…”;
return $blocks;
}
}

/**
* Implementation of hook_help()
*/

function moduleName_help($path, $arg){
if($path == ‘admin/help#moduleName){
$txt = ‘The moduleName module uses the !subThisHolder_url API ‘;
$link = l(‘copyForTheAnchorTag’, ‘http://www.moduleName.com’);
$replace = array(!subThisHolder_url‘ => $link);
return ‘<p>’ . t($txt, $replace) . ‘</p>’;
}
} //end of example .module code…

Other things useful of note:

The watchdog() function: http://api.drupal.org/api/function/watchdog/6
watchdog(‘loggingCategoryNameThisModuleNameMostLikely’, $msg, $varsToSubIntoMsg, WATCHDOG_WARNING):
logging options:
WATCHDOG_EMERG
WATCHDOG_ALERT
WATCHDOG_CRITICAL
WATCHDOG_ERROR
WATCHDOG_WARNING
WATCHDOG_NOTICE
WATCHDOG_INFO
WATCHDOG_DEBUG

check_plain()http://api.drupal.org/api/function/check_plain/6

check_url() http://api.drupal.org/api/function/check_url/6

t() example:

t(‘Replacing %value by !urlHere for @emailPerhaps ‘, array(‘%value’=>’test’, ‘@emailPerhaps’=>$email, ‘!urlHere’=>’http://blah.com’);

!placeholders replaced as is, @placeholders replaced effectively “escaped by” check_plain(), %placeholders are replaced themed as well

Comments are closed.