I was trying to override the theme_comment_post_forbidden in order to
hide the "login or register to post comment" link.

The problem is that this is not possible because with the code

$links[] = theme('comment_post_forbidden', $node->nid);

an entry on the links array is always made even if the theme call return NULL or nothing.

So overriding theme('comment_post_forbidden', $node->nid); with a function which always
return '' or NULL always make an entry on $links array which is the rendered as " | ...".
All links will starts with a blank and | .

The attached patch solved this.

CommentFileSizeAuthor
post_forbidden_link_themeable.patch629 bytesfax8

Comments

Tobias Maier’s picture

you are using theme_links() to theme the link array?
why not change it this way that it ignores (automatically delets) blank array-values?

fax8’s picture

it could be a solution... but I still think that my patch is useful...
comment.module should check for returned values of the theme function.

moshe weitzman’s picture

Status: Needs review » Needs work

the patch is a bit verbose and Tobias suggests a good workaround which doesn't add more code.

fax8’s picture

could be reasonable making theme_links strip null values by default?

markus_petrux’s picture

If thinking about hook_link(), as I believe this is something that's not only related to the comments module, may I point to these issues:

* Allow overriding of links returned by modules
* Add the weight concept for node links

This is another issue that's specific to the "login to post comments" link:
* "login to post comments" confusing?

Jaza’s picture

Version: x.y.z » 6.x-dev

This is not such a big deal now that hook_link_alter is in core, but this should still be properly overridable through the theme function, not just through hook_link_alter(). Or, maybe we don't need the theme function anymore, since hook_link_alter can do the job instead? Either way, a patch for this is still needed.

sun’s picture

Title: make theme_comment_post_forbidden nullificable » Allow theme_comment_post_forbidden() to return NULL (nothing)
Version: 6.x-dev » 7.x-dev
Assigned: fax8 » Unassigned
Category: bug » task
Status: Needs work » Closed (won't fix)

Since themes can participate in alter hooks in Drupal 7, an attempt to make the theme function return nothing would be bogus in the first place. Instead, a theme can implement hook_node_view_alter() and play with it as desired.

lizaazad’s picture

Impressive solve with The attached patch as well! Just a quick note to tell you that I have a passion for the topic "the theme_comment_post_forbidden" at hand. I would like to write an best essay about it. Thanks.