Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
i get some notices
Notice: Undefined index: comment_count in ohm_preprocess_node() (line 12 of /var/www/sites/all/themes/omega/ohm/preprocess/node.preprocess.inc).
and the following output in node teasers:
Friday, July 26, 2013 - 16:17 | Author: admin | Comments ()
Comment | File | Size | Author |
---|---|---|---|
#7 | omega-undefined_comment_count-2057945-7.patch | 1.07 KB | Anthony Fok |
#6 | omega-undefined_comment_count-2057945-6.patch | 746 bytes | Anthony Fok |
#5 | omega-undefined_comment_count-2057945-5.patch | 747 bytes | Anthony Fok |
#2 | omega-undefined_comment_count-2057945-2.patch | 747 bytes | Anthony Fok |
Comments
Comment #1
fubhy CreditAttribution: fubhy commentedYep, confirmed. @splatio? Want to provide a fix? Probably just means to check for the comment variables in the node preprocessor?
Comment #2
Anthony Fok CreditAttribution: Anthony Fok commentedI encountered the exact same problem as I was working on my website. It appears that #2042437: Undefined index: comment_count in ohm_preprocess_node() fixed the problem, but did not cover all cases.
Attached is a patch that uses a different way,
!empty($node->comment_count)
, to detect the existence of comment_count. I borrowed this method fromnode_title_list()
in module/node/node.module in Drupal 7 core, and it seems to work well here.A side effect: "Comments (0)" is no more. That part would only be displayed if there is at least one comment posted for that node.
Comment #3
fubhy CreditAttribution: fubhy commentedWhat you wrote there is the exact same logic just with different (nicer) code.
;)
Comment #4
fubhy CreditAttribution: fubhy commentedI think having "Comments (0)" is something we should try to retain. So we need a different solution. I am sure there is a better way. Will look into it tomorrow unless you want to try again Anthony? :)
Comment #5
Anthony Fok CreditAttribution: Anthony Fok commentedThanks for the encouragement, and the big hint that you gave me. ;-)
The patch is now revised to keep "Comments (0)".
Please review. Many thanks!
Comment #6
Anthony Fok CreditAttribution: Anthony Fok commentedSorry, I made a huge "Brown Paper Bag" mistake... I updated my test theme without actually updating the copy in the git tree before making the patch... (very embarrassed) ;-)
Here is the patch again. Thanks!
Comment #7
Anthony Fok CreditAttribution: Anthony Fok commentedAnother revised patch that (I hope) follows the DRY principle better. :-)
Comment #8
fubhy CreditAttribution: fubhy commentedLooks good. Did not test it though. Does this work now in all situations?
Comment #9
Anthony Fok CreditAttribution: Anthony Fok commentedYes, it works well here on my computer. Perhaps other people can help test it too.
Comment #10
fubhy CreditAttribution: fubhy commentedCommitted, thanks.