function hook_node_view_alter
Alter the results of node_view().
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 node content structure has been built.
If the module wishes to act on the rendered HTML of the node rather than the structured content array, it may use this hook to add a #post_render callback. Alternatively, it could also implement hook_preprocess_node(). See drupal_render() and theme() documentation respectively for details.
Parameters
$build: A renderable array representing the node content.
See also
Related topics
2 functions implement hook_node_view_alter()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- CommentHooks::nodeViewAlter in core/
modules/ comment/ src/ Hook/ CommentHooks.php - Implements hook_ENTITY_TYPE_view_alter() for node entities.
- HistoryHooks::nodeViewAlter in core/
modules/ history/ src/ Hook/ HistoryHooks.php - Implements hook_ENTITY_TYPE_view_alter() for node entities.
File
-
modules/
node/ node.api.php, line 862
Code
function hook_node_view_alter(&$build) {
if ($build['#view_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 node.
$build['#post_render'][] = 'my_module_node_post_render';
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.