Add the ability to change / update the comment wrapper title when a comment is added / deleted.

In our use case, the number of comments on the node is displayed as '# comments' - which is not changed when a new comment is added.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Cook created an issue. See original summary.

John Cook’s picture

Status: Active » Needs review
FileSize
2.29 KB

I have solved this be creating a hook which is processed when a comment is added or deleted. This gives developers the ability to tailor the title to there requirements without having to hack ajax_comments and end up with unsupported code.

The hook hook_ajax_comments_title() expects a node id and returns the new title or NULL if it isn't to be changed.

formatC'vt’s picture

Status: Needs review » Needs work

Thanks, nice feature, but i think we should implement something like hook_ajax_comments_custom_commands (and custom commands for _insert, _delete, etc), not a wrapper title specific hook.
What do you think?

John Cook’s picture

I've refactored #2 to use the more generic hook_ajax_comments_custom_commands(). I've added insert and delete hooks so different ajax command can be called. Also, I've created hook_ajax_comments_custom_commands_alter() so the commands array can be inspected, and changed if necessary, by other modules.

The order the hooks are called is:

  1. Common; hook_ajax_comments_custom_commands()
  2. Specific; is hook_ajax_comments_custom_commands_insert()
  3. Alter; hook_ajax_comments_custom_commands_alter()

Attached is test_ajax_comments.zip. This contains a module to check the hooks are working. For each hook, it dpm()s the passed in parameter and also puts it in the 'Recent log messages' table (the page needs to be refreshed to get the dpmed output to be displayed). The common hook also changes the title of the comment section and uses the same code as in ajax_comments.api.php.

John Cook’s picture

Status: Needs work » Needs review