Hacks Listing

Events happening in the community are now at Drupal community events on www.drupal.org.
michelle's picture

I've been searching through the forums looking for stuff to help me customize my forums. I've found some snippits and hacks and thought I'd gather the links here. Warning: Some of these hack core, which is really not recommended.

Add pager to top of page:
http://drupal.org/node/79352#comment-148773
http://drupal.org/node/79352#comment-223909

Replace text links with buttons:
http://drupal.org/node/56127#comment-111222

Change "add new comment" to "reply":
http://drupal.org/node/78562#comment-145094

Moving the forum header:
http://www.hiveminds.co.uk/node/913#comment-253

That's if for now... Will add more as I find them.

Michelle

Comments

Change comment links

heine's picture

We have a hook_link_alter nowadays that can be used to change the link. One could also change $node->links['comment_add']['title'] in node.tpl.php and then - instead of print $links - use print theme('links', $node->links, array('class' => 'links inline')).

This can be beautified by moving the code to template.php's variable hook.

Elaborate, please?

michelle's picture

I tried to do the template.php route, but I don't think I know what I'm doing enough. There is this code there already (from flatforum):

    $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];

So immediately before it I put:

    $vars['links']['comment_add']['title'] = "reply";

I also tried doing

    $variables['links']['comment_add']['title'] = "reply";

Neither of those had any effect. What should I be putting there?

Thanks,

Michelle

Links isn't the right

heine's picture

Links isn't the right variable here, because it is a holding a string (links in HTML) set in phptemplate_node (themes/engines/phptemplate.engine: 272):

<?php
'links'          => $node->links ? theme('links', $node->links, array('class' => 'links inline')) : '',
?>

What you need to modify is $node->links, then regenerate $links to hold the new info, which would go a bit like:

<?php
function _phptemplate_variables($hook, $vars) {
// rest of the _phptemplate_variables function

// Now, in $hook == 'node':
if (!empty($vars['node']->links) && !empty($vars['node']->links['comment_add'])) {
 
$vars['node']->links['comment_add']['title'] = t('Reply');
 
$variables['links'] = theme('links', $vars['node']->links, array('class' => 'links inline'));
}
?>

(standard syntax error disclaimer applies)

Works great

michelle's picture

I just had to comment out the original flatforum line and it worked. Thanks!

Michelle

Not working

jiangxijay's picture

Does anyone know if this still work in 5.2/garland?

I get an error: syntax error, unexpected $end"

Perhaps there is something in your syntax error disclaimer that I don't know yet as a newcomer ... ;)

Typo

niklp's picture

phptemplate.engine uses the variable name "$variables" but in the example, "$vars" is being used.

The correct syntax for the final line is:

$vars['links'] = theme('links', $vars['node']->links, array('class' => 'links inline'));

This is just a consistency thing... hope it helps.

Web Development in Nottingham, UK by Kineta Systems

Getting forum header to work in Drupal 5

kpk-gdo's picture

Thanks for the listing. However, I don't quite get the forum header solution to work with Drupal 5. Any suggestions?