Hi,

I've searched for a while and couldn't find a definite answer. So I apologize if I am blind and there's and answer somewhere.

I'm writing a module that returns dynamically generated pages (e.g. like the module tutorial shows on this page: http://drupal.org/node/82968 )

However, I would like to have an "add comments" link at the bottom of the generated pages. Is this possible without installing a bunch of other modules or creating arcane content types?

I've looked at hook_link, hook_view and hook_nodeapi, but they don't get called if it's not a node.

I'm looking for a simple solution, or some alternatives.

Thanks.

Comments

Andargor’s picture

Just thought of something else: if it's possible to attach a comment to a URL instead of a node, would that be feasible somehow? The generated pages could have unique URLs.

ahaapaka’s picture

This does not help in your problem, but...

I'm a drupal-newbie and I was also just pondering what is the proper way of displaying links on dynamically generated page since the hook_link() is only for nodes.

I ended up using theme_links():

function mymodule_content() {

  $content = '<p>Time is an illusion. Lunchtime doubly so.</p>';

  $links['foo'] = array(
    'title' => 'Foo',
    'href' => 'xyzzy/foo' );

  $links['bar'] = array(
    'title' => 'Bar',
    'href' => 'xyzzy/bar' );

  $content .= theme('links', $links);

  return $content;
}

It is very unfortunate, if comments can be attached only to nodes and other comments. I was planning to enable commenting on every page of my site, but it seems impossible.

matthew_ellis24’s picture

I have a similar problem. My dynamic pages all have unique species_id's so it should be possible to insert the species_id (or similar unique identifier) into the comments tables in the database. Then recall comments according to node id and species_id (or your unique identifier). I had a look at the comments.module but ended up breaking it :)

Has there been any progress on this?

More of my predicament here:
http://drupal.org/node/212979

matthew_ellis24’s picture

This is what I tried. It didn't work, but it didn't break it, so I obviously missed something, or more likely, several things. Maybe it's a helpful starter for someone. Numbers are line numbers, and my changes are the bits where $species_id appears. Like I said, I've obviously missed out loads, but I don't know where, and it still works at least!

I added a species_id column to the comments table, made a comment on the right node, and then went in to the database and manually assigned it a species_id. So at least there's something there for it to display if I ever get it working!

428: $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = %d AND species_id = "$species_id"', $node->nid, COMMENT_PUBLISHED);

720: $duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s' AND species_id = '$species_id'", $edit['pid'], $edit['nid'], $edit['subject'], $edit['comment']), 0);

787: db_query("INSERT INTO {comments} (cid, nid, pid, uid, species_id, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '$species_id', '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], $_SERVER['REMOTE_ADDR'], $edit['timestamp'], $edit['status'], $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']);

972: $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d  AND species_id = "$species_id"';

Then at the beginning somewhere I added this mess just to be certain it was being defined:

$spid = $_GET['spid'];
if (!empty($spid)){
$species_id=$spid;
}else{
$species_id=$_POST['subcat4'];
}
if(empty($species_id));{
$species_id=0;
}