I am trying to load a specific revision for viewing by the end user. Drupal 7.
I have the following in my .module ;
function mymodule_node_load($nodes, $types) {
if ($nodes[821]->vid != 5928) {
$nodes[821] = node_load(821, 5928);
}
}
function mymodule_node_view($node, $view_mode, $langcode) {
$node = node_load(821, 5928);
}
If I dpm/var_dump the node after doing this, its perfect and is the correct revision but when it comes to rendering, the page chooses the older revision. So something is happening between these functions and the page rendering. What is it? And how can I stop it?
Thanks in advance, much appreciated.
EDIT Anybody know if there is a hook load order chart somewhere? That would be super handy.
EDIT #2 It seems that even the node.tpl.php has the correct revision but what is displayed is not the correct revision ... See image (body['und'][0]['value'] != what is displayed.)
EDIT #3 Ok, so I worked out how to do it (code below) its an awful solution and its because of this that I am going to have a look at the Workbench module because I think it might just do what I need. Thanks for all the help!
/**
* Implements hook_node_view_alter().
*/
function mymodule_node_view_alter(&$build) {
$latest_revision = _get_latest_published_revision($build['#node']);
if ($latest_revision) {
$build['#node'] = node_load($build['#node']->nid, $latest_revision);
node_build_content($build['#node']);
$build['body'] = $build['#node']->content['body'];
}
}