When I use the code in genesis template.php
/**
* Add a "Comments" heading above comments except on forum pages.
*/
function genesis_preprocess_comment_wrapper(&$vars) {
if ($vars['content'] && $vars['node']->type != 'forum') {
$vars['content'] = '

'. t('Comments') .'

'. $vars['content'];
}
}
there are two 'Comment' render at page! Can you solve it?
eZar

CommentFileSizeAuthor
#7 568522_theme.patch410 byteseporama
#7 theme_debug.patch1.19 KBeporama
#4 568522.patch1.11 KBeporama
image.JPG10.06 KBezar
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eporama’s picture

I can confirm this as a problem with the base genesis-6.x-2.4 theme and my subtheme based on that, however it doesn't happen for any of the prepackaged genesis subthemes.

I still can't confirm why, but if I remove the subtheme's comment-wrapper.tpl.php the preprocess function is only called once. Hopefully this can help until the issue can actually be tracked down in code.

Jeff Burnz’s picture

You need to look at what you are doing differently and/or what modules you have installed and how they might be changing the code or templates and so on because this simple not a problem I have ever seen, and in so many years + thousands of users this has been reported once with only one reply in over a year.

eporama’s picture

I should have also mentioned that I can replicate this on a completely fresh Drupal 6.19 install with nothing but genesis downloaded as contrib. I understand that it's not common, but I wonder how many people are using genesis without using a subtheme. This happens with "genesis" as the theme, but not with any of the supplied subthemes, I only noticed it because it happens to *my* subtheme and I was able to track it back and replicate it in the base genesis theme. I'm not 100% sure it's a fault w/genesis, except that I can't trace why genesis_preprocess_comment_wrapper() gets called twice.

EDIT: here are two threads that I was hoping might lead to some enlightenment, but they seem to have been fixed and I would have thought their fixes would have taken care of this issue #252430: Allow BASETHEME_ prefix in preprocessor function names and #258089: Themes cannot have a preprocess function without a corresponding .tpl.php file

eporama’s picture

Status: Active » Needs work
FileSize
1.11 KB

Okay, part of problem solved... I had a leftover section from when I upgraded the subtheme from 1.x to 2.x

/**
 * Implementation of HOOK_theme().
 */
function genesis_ltd_theme(&$existing, $type, $theme, $path) {
  $hooks = genesis_theme($existing, $type, $theme, $path);
   Add your theme hooks like this:
  /*
  $hooks['hook_name_here'] = array( // Details go here );
  */
  return $hooks;
}

Removing that certainly solved my problem on the subtheme, but I can still have this happen when using the base genesis theme. So if this ever gets back to ezar or if anyone else has the issue, hopefully a place to start looking.

One issue, however, is that you cannot change the 'Comments' H2 in a subtheme because the subtheme calls genesis_preprocess_hook functions as well as its own. And the base genesis function concats the H2 directly to $content. Could it make sense to pass that heading in as a variable instead? I attached a patch for that. Can't imagine that it's enough, but just curious about the reasoning behind the concat. This solves both issues (duplication and overridability).

Jeff Burnz’s picture

Could be a better idea to shift this to the template, which would make it easier to change - in some of my other themes I have moved this to the template already.

May I ask why you need/want to change the H2, just out of interest.

eporama’s picture

Well, to be honest, I came across this issue while trying to debug the problem that I had actually caused by upgrading poorly, so I don't need to yet. But here's a hypothetical, based on one way that a site I helped with last summer was built.

They had a specific content type for "Question" and were using the Comment mechanism as an "Answer", so they wanted to change "Comments" to "Answers", since the wrapper preprocess has t('Comments'), we could override the string, but that would be sitewide. As it stands now we couldn't use the preprocess to change the heading, we could only add onto it... With the patch above, you are resetting the title, instead of adding it directly to $content.

eporama’s picture

Status: Needs work » Needs review
FileSize
1.19 KB
410 bytes

I think I found the "culprit"... in template.php, genesis_theme calls

  $templates = drupal_find_theme_functions($existing, array('phptemplate', $theme));
  $templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
  return $templates;

when phptemplate registers its preprocess functions for genesis, it finds all of the necessary functions, when genesis registers and calls drupal_find_theme_templates directly, it adds the functions to the queue directly which doubles them.

So far in testing, removing the line with drupal_find_theme_templates does not appear to affect anything. All of the necessary preprocess functions are included and we seem to be good to go...

I'm attaching the core debug hack I used (modifies includes/theme.inc to put up some drupal_set_message lines) and the absurdly simple patch to genesis/genesis/template.php which seems to fix the problem without any adverse side effects that I can find. You only need the theme.inc patch if you want to see before/after effects of the other patch.

This fixes the original post problem of duplication of the Comments H2 element. However the other patch may still be useful to be able to override the preprocess function in a subtheme.

If I'm missing something crucial about what the drupal_find_theme_templates is doing here, I'd love to know about it.