hook_comment_build_alter

Versions
7
hook_comment_build_alter($build)

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.

See also

comment_build()

Parameters

$build A renderable array representing the comment.

Related topics

Code

modules/comment/comment.api.php, line 91

<?php
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';
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.