summaryrefslogtreecommitdiff
path: root/modules/comment
diff options
context:
space:
mode:
Diffstat (limited to 'modules/comment')
-rw-r--r--modules/comment/comment.api.php28
-rw-r--r--modules/comment/comment.module9
2 files changed, 32 insertions, 5 deletions
diff --git a/modules/comment/comment.api.php b/modules/comment/comment.api.php
index 104562e34..c9b8da1a3 100644
--- a/modules/comment/comment.api.php
+++ b/modules/comment/comment.api.php
@@ -73,6 +73,34 @@ function hook_comment_view($comment) {
}
/**
+ * The comment was built; the module may modify the structured content.
+ *
+ * This hook is called after the content has been assembled in a structured array
+ * and may be used for doing processing which requires that the complete comment
+ * content structure has been built.
+ *
+ * If the module wishes to act on the rendered HTML of the comment rather than the
+ * structured content array, it may use this hook to add a #post_render callback.
+ * Alternatively, it could also implement hook_preprocess_comment(). See
+ * drupal_render() and theme() documentation respectively for details.
+ *
+ * @param $build
+ * A renderable array representing the comment.
+ *
+ * @see comment_build()
+ */
+function hook_comment_build_alter($build) {
+ // Check for the existence of a field added by another module.
+ if ($build['#build_mode'] == 'full' && isset($build['an_additional_field'])) {
+ // Change its weight.
+ $build['an_additional_field']['#weight'] = -10;
+ }
+
+ // Add a #post_render callback to act on the rendered HTML of the comment.
+ $build['#post_render'][] = 'my_module_comment_post_render';
+}
+
+/**
* The comment is being published by the moderator.
*
* @param $comment
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index a8c014bf5..efedac972 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -794,8 +794,6 @@ function comment_build($comment, stdClass $node, $build_mode = 'full') {
'#node' => $node,
'#build_mode' => $build_mode,
);
- // Add contextual links for this comment.
- $build['#contextual_links']['comment'] = menu_contextual_links('comment', array($comment->cid));
$prefix = '';
$is_threaded = isset($comment->divs) && variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED) == COMMENT_MODE_THREADED;
@@ -819,6 +817,9 @@ function comment_build($comment, stdClass $node, $build_mode = 'full') {
$build['#suffix'] = str_repeat('</div>', $comment->divs_final);
}
+ // Allow modules to modify the structured comment.
+ drupal_alter('comment_build', $build);
+
return $build;
}
@@ -844,6 +845,7 @@ function comment_build_content($comment, stdClass $node, $build_mode = 'full') {
'#markup' => check_markup($comment->comment, $comment->format, '', TRUE),
);
+ // Build fields content.
field_attach_prepare_view('comment', array($comment->cid => $comment), $build_mode);
$comment->content += field_attach_view('comment', $comment, $build_mode);
@@ -857,9 +859,6 @@ function comment_build_content($comment, stdClass $node, $build_mode = 'full') {
// Allow modules to make their own additions to the comment.
module_invoke_all('comment_view', $comment, $build_mode);
-
- // Allow modules to modify the structured comment.
- drupal_alter('comment_build', $comment, $build_mode);
}
/**