header photo

via positiva

...And while I'm at it

One of the topics that comes up occasionally on Drupal.org is the idea of comments as nodes. For those who haven't dug into the system's innards, almost all content on a Drupal site is stored as a 'node.' Different kinds of nodes (images, quotations, blog entries, weblinks, etc.) can have additional data fields and different presentaiton, but they all get to leverage the same core infrastructure of the node api. Comments, on the other hand, are a special kind of content that sits in its own separate table. Adding features to the commenting system is, by nature, a lot more difficult and only really possible with Drupal 4.7's enhanced form building API.

A good case can be made for keeping comments separate. On sites with huge numbers of comments, it speeds up queries for the code nodes table. It's also relatively join-friendly, as making comments into a type of node would still require an auxiliary 'comment_data' table, or somesuch. On really high-traffic sites, that's a pain and a half: pulling data from the node table and joining to it is already one of the things Drupal does most often, and anything that slows it down unecessarily is bad.

That said, though, I think that it could still be a noble goal. Certain core functions (say, file attachments, saving edits in revisions, and so on) would come 'for free' if nodes were used for commenting. Three specific cases come to mind where wthis would be useful. The first is the 'microfiction' content type I created a while back for Drupal 4.6. The name was a misnomer -- in reality it was a microfiction contest -- the comments on the node were the actual stories. I would've much rather seen each response be treated as an actual node. Another is Something Awful style photoshop contests. Instead of simply posting images inline in comments, each comment could be an actual image node -- automatically added to the appropriate gallery. And finally, the forum module that works well but gets so many complaints. With comments as nodes, the ability to split a discussion thread -- taking one comment and its children and promoting it to a full-fledged new topic -- would be rather more straightforward. Promoting great comments to the front page -- just as one would a node -- would also be simple.

If the system were flexible enough to utilize different kinds of nodes as comments, things like photoshop image contests, audio remixing contests, etc would all be much easier. In addition to turning comments on or off for a given node type, one could choose between the 'default' comment type, images, audio, etc. A while back, javanaut's interesting relativity module supported something kind of like that. Administrators could configure parent/child relationships between different kinds of nodes, even enforcing cardinality in some cases. That might be going a bit far, but it would be cool -- very cool -- to support that sort of relationship in commenting.

Naturally, ideas like this get little interest with Drupal 4.7's release around the corner and much bug-hunting still going on. But the groundwork that 4.7 lays make this feature a lot more feasible. The Forms API makes 'remixing' content creation forms a piece of cake, for example. The more I think about it, the higher this rises on my list of personal projects for 2006.

Comments as Node

The nice thing about comments as node (and user profile as node) is that you can do 'recent comments' and various other comment tricks with Views basically for free.

Though interestingly, it would probably be relatively trivial to modify Views to do user/comment listings. The query engine can handle it.

True, that

Views is scarily flexible for stuff like that. Part of the reason this has me thinking, though, is the need for a more flexible hierarchial posting system for another project. It would involve discussions can evolve into new threads without explicit administrator 'conversion,' among other things. Replies would be posted against the 'term_node' level of specificity rather than just 'node.' And tagging a comment with a new term would cause it to become its own top-level topic, with replies to the comment appearing in the context the comment was read.

It's the sort of system that's doable with distinct nodes, but nigh impossible with the current comment system...

lets not overstate the

lets not overstate the problem. it would be a minor job to make a module which split a discussion thread and reposted the first comment in the branch as a new forum topic or whatever was needed.

This is true...

...but the site I'm talking about would be a lot more ambitious. The idea is that the piece of content in question would not be *duplicated*, just referenced in multiple locations. A bit like branching in a good source control system. In addition, the need to classify comments via taxonomy would be a big issue.

I'm not suggesting that everyone would want a system of that complexity, not by any means.

Another good reason for comments as nodes.

You get node level access permissions for free.

And the upload module for instance would magically work on all comments.

Oh, and cck node types as comments, which would be _awesome_ for a flexible trouble ticketing system.

You'd probably also end up being able to get rid of a fair amount of code in the process too.

Can you not build a module that does this?

Just to be clear: are you talking about changes to core, or building a module that does this? Seems like all the hooks you need to define a comment node type (or allow any node to be a comment) are already in drupal.

Or am I missing something?

Well...

I it could be done by swapping in a different module. Right now, though, comment.module is all but a required piece of core. There are a lot of assumptions about the nature of the commenting system in other non-comment modules. node.module, for example, would have to be altered in a number of key places. Forum.module would have to be replaced entirely, of course.

It's certainly possible, though, that the 'traditional' commenting system could be left in place with some API changes for greater flexibility, and a new node-based system could be distributed as a contrib module.

very interesting

Jeff,
thank you for writing this very interesting explanation.

We posted it on
http://www.drupalecommerce.com
/node/306

Merlin, we are using your Recent Comments block, which we like very much.

Another Vote for Comments-as-Nodes to be an option

Creating an API that allows for both the current system and new systems for sites with more featureful comments sounds like a *very* good idea.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <img> <i> <b> <strike> <h3> <h4>
  • Lines and paragraphs break automatically.
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Miniblog

  • Curious about using Drupal? @walkah and I will be hosting an O'Reilly webcast about it on Friday, December 5th! http://oreilly.com/go/drupal 2 hours ago
  • @ejhildreth back-of-the-envelope math indicates that for the price of the bailout, we could give $2000 to every family living in poverty. 2 hours ago
  • Irony is Karl Rove lecturing Obama not to politicize the process of appointing states attorneys. 3 hours ago
  • Best summary ever: "My name is Ulrich Haarbürste and I like to write stories about Roy Orbison being wrapped in cling-film." Oh, Internets. 7 hours ago
  • @domesticat I believe you're thinking of the "NOM NOM Award for Excellence in Open Source" 7 hours ago