ARCHIVE: Converting 3.0.x themes to 4.0.x
Last modified: February 1, 2009 - 15:27
Required changes
Changes in class definition
Theme class definition uses now a different syntax:
Instead
class Theme extends BaseTheme {you should use
class Theme_<i>themename</i> extends BaseTheme {where themename is name of your theme in lowercase.
Changes in function header()
- Function header() takes now an optional parameter $title.
Instead
function header() {you should use
function header($title = "") { - Previously all pages in Drupal site had the fixed page title: sitename - site slogan. Now the page title can be dynamic - for example when displaying single node, the page title can be note title - sitename. So, instead
print variable_get("site_name", "drupal") ." - ". variable_get("site_slogan", "");you should use a more complex syntax:
of if you want to use compact version of the same construction:if ($title) {
print $title ." - ". variable_get("site_name", "drupal");
}
else {
print variable_get("site_name", "drupal") ." - ". variable_get("site_slogan", "");
}
This piece of code checks if $title is present. If yes, it outputs $title and site name, if not, it outputs site name and slogan.print $title ? $title." - ". variable_get("site_name", "drupal") :
variable_get("site_name", "drupal") ." ". variable_get("site_slogan", ""); - If you used theme_account() function (what outputs login/membership box) in header(), please remove it. Login box placement is controlled in Administration > blocks page from now on and theme_account() is no longer used.
Changes in function node()
- format_name() accepts now parameter $node, not $node->name. Also $node->timestamp is replaced with $node->created. So, instead
print strtr(t("Submitted by %a on %b"), array("%a" => format_name(<b>$node->name</b>), "%b" => format_date(<b>$node->timestamp</b>)));you should use
print strtr(t("Submitted by %a on %b"), array("%a" => format_name(<b>$node</b>), "%b" => format_date(<b>$node->created</b>))); - node_index() is no longer used because Drupal 4.0 has more sophisticated classification system than Drupal 3.0 meta tags. So instead plain simple
print node_index($node);you have to use
$terms = array();
if (function_exists("taxonomy_node_get_terms")) {
foreach (taxonomy_node_get_terms($node->nid) as $term) {
$terms[] = l($term->name, array("or" => $term->tid), "index");
}
}
print $this->links($terms); - Function link_node() accepts an optional parameter $main. Instead
you should useif ($main) {
print $this->links(link_node($node));
}
you should useif ($links = link_node($node, $main)) {
print $this->links($links);
} </li></ul><h2>Changes in function comment()</h2>
<ul><li>format_name() accepts now parameter $comment, not $comment->name. Instead
<code> print strtr(t("Submitted by %a on %b"), array("%a" => format_name(<b>$comment->name</b>), "%b" => format_date($comment->timestamp)));
print strtr(t("Submitted by %a on %b"), array("%a" => format_name(<b>$comment</b>), "%b" => format_date($comment->timestamp)));
Changes in function footer()
- If you used theme_account() function (what outputs login/membership box) in footer() function, please remove it. Login box placement is controlled in Administration > blocks page from now on and theme_account() is no longer used.
Optional changes
New function: system()
- Optionally theme can have a system() function what provides info about theme and its author:
function system($field) {
$system["name"] = "theme name";
$system["author"] = "author name";
$system["description"] = "description of the theme";
return $system[$field];
}
