Problem/Motivation
In at least one instance, after the node view is built via node_build_content, the some of the standard alter hooks are not invoked as might be expected.
Line 204-206 in quiz_question.module, specifically.
node_build_content($node, 'question');
unset($node->content['answers']);
unset($node->content['links']);
In the Node module, the following snippet happens in node_view() after calling node_build_content().
// Allow modules to modify the structured node.
$type = 'node';
drupal_alter(array('node_view', 'entity_view'), $build, $type);<
Proposed resolution
Consider calling node_view() instead of node_build_content(). This will invoke hook_node_view() and hook_node_view_alter() (and the entity counterparts) without having to explicitly do it in this module.
If there are reasons that calling node_view() was avoided, just make sure that this and other instances of view building are followed by
// Allow modules to modify the structured node.
$type = 'node';
drupal_alter(array('node_view', 'entity_view'), $build, $type);<
Comments
Comment #1
djdevinThere were issues using node_view() since it renders the title and other things as well so we used node_build_content().
I agree I think manually invoking that hook would be the way to go.
Comment #2
wwedding commentedYeah, you end up having to add at least 4 additional lines just to unset all the extra stuff that this module doesn't care about. It looks nicer just invoking the alter hooks.
Comment #3
djdevinLooks good. Thanks!
Comment #5
wwedding commentedSorry, I found another case that I missed. I should've done a thorough search in all the files before making that patch. Nothing else I've missed at this point, though.
Comment #8
djdevinFixed some more!
Tests are fine, the random one fails from time to time (because it is random).
Comment #9
djdevinWhoops, got a fatal on this one.
hook_node_view_alter
and
hook_entity_view_alter
Both take $build as input, not the node. They should receive the render array generated by node_view or entity_view().
Comment #10
djdevin