Hello - this is the first time I've tried using Ctools myself and I'm a bit confused. I want to use the ctools_comment_render() function, and having looked around all over the place I think I can see where it is (sites\all\modules\ctools\plugins\content_types\node_context\node_comments.inc).
The problem is, that when I try to use a call to the function in my code I get an "undefined function" error.
I looked around some more and tried using ctools_include('plugins') but this does no good and to judge by the error message is not looking in the right place, so clearly I am getting something wrong.
I would be very grateful for some help on this.
Comments
Comment #1
merlinofchaos commentedYou're looking at code that is part of a CTools content type plugin, and not really intended to be called directly. That function only exists to deal with Core being a little too difficult to work with, so CTools has its own version of the function.
If you aren't using a content type plugin as a plugin, you probably don't want to call that function directly. Perhaps you want to clone it and tailor it to do what you need.
Comment #2
joel_guesclin commentedThanks for taking the time with this. The reason I am doing this, is to upgrade the DiscussThis module to D7. DiscussThis basically stops users from adding comments to an article (or other node) by diverting the comments into a Forum thread (I'm oversimplifying but that's the basic idea). However, it also offers the possibility of displaying the forum thread under the original article as well. At the moment it does this by cloning the original comment_render() function from D6, which has now disappeared. I could have done a clone, indeed I did think of cloning ctools_comment_render(), but I hate proliferating bits of code which essentially do the same thing.
So basically, what I am trying to do is call ctools_comment_render() to get the comments from a forum thread, and attach the comments to the display of the article which originated the forum thread.
I confess I'm hacking this somehat, since I don't understand how ctools works at all (and haven't been able to find documentation explaining the general principles, oddly - I presume there must be some but would be glad of a pointer to where), and I understand from what you're saying that I would use anything from Ctools "at my own risk".
All that said, I think I have more or less gotten this to work:
Comment #3
merlinofchaos commentedDoing that would actually break the plugin, so please don't do it that way.
You want to do:
If you don't do this, if something else on the page happens to use that particular plugin on the page afterward, because you loaded that file manually the $plugin = array() at the top of it will be lost and the plugin will mysteriously disappear.
Comment #4
merlinofchaos commentedAlso, there are many resources you can find to understand how CTools plugins work -- there are at least half a dozen tutorials of various quality, plus the info in the advanced help on plugins, and the ctools example module contains implementations of plugins. Of course, most of this is irrelevant to you -- you aren't actually using this as a plugin.
Comment #5
joel_guesclin commentedMany thanks, again, for taking the trouble. In the end I decided to got with your advice and extract the bits I needed from the function. But I will keep this as a reference just in case!