Improvement: Made tracker2_page() themeable. Divide tracker2_page() into 2 functions so other modules can reuse code.
| Project: | Tracker 2 |
| Version: | 5.x-1.12 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
| Issue tags: | themability, themable, tracker2 |
The tracker2 tracker2_page() function combines the retrieval of nodes with the display of nodes. Further, since the display runs through the system-default theme functions for a table, there is very little control over the presentation of the tracker2_page, unless the site admin is willing to modify the display of *all* tables on the site.
My patch modifies the tracker2_page() function by splitting it up, so that the retrieval and presentation parts of the logic are separate. This facilitates code reuse, rather than having to copy/past the tracker2_page() function into whatever custom logic one is working on, and modifying that.
tracker2_page() //assembles nodes list, and adds new comment info
tracker2_get_nodes_for_user() //gets the "raw" node list
theme_tracker2_page() // implements theming so site designers can customize the display.
Also, my patch includes a minor bug fix. In version 1.x-1.12, line 369, we see:
else {
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5'));
}
Notice: The array $rows has not been defined yet for this branch of the logic.
| Attachment | Size |
|---|---|
| themeable_tracker2_module_v1.patch | 4.06 KB |

#1
Note: I realized my patch might not be able to be applied directly, since I had added a few other comments to the tracker2.module. I'll see if I can re-roll with unmodified version 1.13 instead.
#2
Attaching a (hopefully) better patch.
#3
Since posting the patch, I realized in changing the code around I left the $rows = array() declaration in the wrong place.
It should be removed from tracker2_page():
<?php
function tracker2_page($uid = 0) {
drupal_add_css(drupal_get_path('module', 'tracker2') .'/tracker2.css', 'module', 'all', FALSE);
$nodes = tracker2_get_nodes_for_user($uid);
return theme('tracker2_page', $nodes);
}
?>
and added to theme_tracker2_page():
<?php
function theme_tracker2_page($nodes=array()) {
$rows = array();
if (!empty($nodes)) {
foreach ($nodes as $node) {
$last_updated = $node->changed;
// Determine the number of comments:
$comments = 0;
if ($node->comment_count) {
$comments = $node->comment_count;
if ($new = comment_num_new($node->nid)) {
$comments .= '<br />';
$comments .= l(format_plural($new, '1 new', '@count new'), 'node/'. $node->nid, NULL, NULL, 'new');
}
}
$rows[] = array(
check_plain(node_get_types('name', $node->type)),
l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
theme('username', $node),
array('class' => 'replies', 'data' => $comments),
t('!time ago', array('!time' => format_interval(time() - $last_updated)))
);
}
}
else {
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5'));
}
$header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated'));
$output = '<div id="tracker">';
$output .= theme('table', $header, $rows);
$output .= theme('pager', NULL, 25, 0);
$output .= '</div>';
return $output;
}
?>
#4
Can you reroll this patch with the latest comment's changes integrated?