Archive for the ‘Drupal’ Category

Drupal Notes 2: sub-theme derivative of bluemarine : Theme inheritance, overriding, preprocessing

Sunday, August 29th, 2010

add folder to:
sites/all/themes(createThis)/subThemeName(createThis)/

create subThemeName.info (in newly created folder):
; $Id$
name = subThemeName
description = blah blah blah blah blah
version = 1.0
core = 6.x
base theme = bluemarine
stylesheets[all][] = descartes-style.css // copy images from parent theme into sub-theme.
stylesheets[all][] = new.css

finally, create above mentioned new.css (in newly created folder) and add styles you’d like to modify, example:
/*
** Style to override the styles.css in
** bluemarine.css
*/

/*
* Plain white right nav.
*/

#sidebar-right{
border-left: 1px solid #ea940c;
background-color: white;
}

ready to go further? copy any of the following over from bluemarine into yourNewSubTheme and edit away:
page.tpl.php (hint: start here), block.tpl.php, box.tpl.php, comment.tpl.php

even further, you’ve moved $breadcrumb in page.tpl.php to where you’d like it, but you want to edit INSIDE that…
these PHPTemplate functions that render content can be found in yourSite/includes/theme.inc
find the one that spits out the content you’d like to modify, and then create a template.php in your new theme directory and override that function…
example: theme_breadcrumb() uses “>>” as separators, in
yourSite/sites/all/themes/yourNewTheme/template.php (make it)
overwrite theme_breadcrumb() via something like this:


// $Id$
/**
* @page
* Override theme_() functions for the youNewTheme.
*/

// Overrides theme_breadcrumb()
function phptemplate_breadcrumb($breadcrumb){
if (empty($breadcrumb)) return;
$sep = ‘<div>&nbsp;&nbsp;</div>’;
$breadcrumb_string = ‘<div>’ . implode($sep, $breadcrumb) . ‘</div>’;
return $breadcrumb_string;
} // end of template.php example

other PHPTemplate theme functions from includes/theme.inc to investigate:
theme_image(), theme_links(), theme_progress_bar(), theme_username(), theme_table(), theme_item_list()

called as follows:
$variable = theme(‘functionName’, $arg1, $arg2, …) , which looks like this:
$crumb = theme(‘item_list’, $breadcrumb, null, ‘ul’, array(‘class’=>’breadcrumb-items’));

IMPORTANT NOTES/REMEMBER:
- a phptemplate_block() function redefined in template.php will override a block.tpl.php file in template folder!
- if you want to preprocess CONTENT before it’s passed to template.php, thus, instead use phptemplate_preprocess_functions()!
- if you’re NOT making a sub-theme, add to .info this line: engine=phptemplate instead of using the base theme line
- don’t forget to make a nice screenshot.png (150×90)

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

Sunday, August 29th, 2010

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