$node->build_mod = NODE_BUILD_PRINT is only set after the node is loaded.
This means that it is not available in hook_nodeapi() when the load operation is called.
We have to wait for the view op, by which stage the content has been prepared.
It would be more efficient to set the build_mode before the node is loaded so that the raw node structure can be manipulated.
print.pages.inc
function _print_generate_node($nid, $cid = NULL, $format = PRINT_HTML_FORMAT, $teaser = FALSE, $message = NULL) {
global $_print_urls;
// << any reason why $node->build_mode cannot be set here ?
// so that is available when the node is loaded
// We can take a node id
$node = node_load($nid);
if (!$node) {
// Node not found
drupal_not_found();
return FALSE;
}
elseif (!node_access('view', $node)) {
// Access is denied
drupal_access_denied();
return FALSE;
}
drupal_set_title(check_plain($node->title));
//alert other modules that we are generating a printer-friendly page, so they can choose to show/hide info
$node->printing = TRUE;
//use the proper build_mode
$node->build_mode = NODE_BUILD_PRINT;
// Turn off Pagination by the Paging module
unset($node->pages);
unset($node->page_count);
// Make this page a member of the original page's organic group
if (function_exists('og_set_group_context') && isset($node->og_groups)) {
og_set_group_context($node->og_groups);
}
if ($cid === NULL) {
// Adapted (simplified) version of node_view
//Render the node content
$node = node_build_content($node, $teaser, TRUE);
// Disable fivestar widget output
unset($node->content['fivestar_widget']);
// Disable service links module output
unset($node->content['service_links']);
$content = drupal_render($node->content);
// Disable the AdSense module ads
$content = preg_replace('!<div class=[\'"]adsense[\'"].*?</div>!sim', '', $content);
if ($teaser) {
$node->teaser = $content;
unset($node->body);
}
else {
$node->body = $content;
unset($node->teaser);
}
}
$print_comments = variable_get('print_comments', PRINT_COMMENTS_DEFAULT);
if (function_exists('comment_render') && (($cid != NULL) || ($print_comments))) {
//Print only the requested comment (or if $cid is NULL, all of them)
$comments = comment_render($node, $cid);
//Remove the comment forms
$comments = preg_replace('!<form.*?id="comment-.*?">.*?</form>!sim', '', $comments);
//Remove the 'Post new comment' title
$comments = preg_replace('!<h2.*'. t('Post new comment') .'
!', '', $comments);
//Remove the comment title hyperlink
$comments = preg_replace('!(
.*?)(.*?)(.*?
)!i', '$1$2$3', $comments);
//Remove the comment author link
$pattern = '!(<(?:span|div) class="submitted">.*?)(.*?)(.*?)!sim';
if (preg_match($pattern, $comments)) {
$comments = preg_replace($pattern , '$1$2$3', $comments);
}
//Remove the comment links
$comments = preg_replace('!\s*
- .*?
!sim', '', $comments);
if ($cid != NULL) {
// Single comment requested, output only the comment
unset($node->body);
}
$node->body .= $comments;
}
node_invoke_nodeapi($node, 'alter', $teaser, TRUE);
$content = theme('print_node', $node, $teaser, TRUE, $format);
if ($teaser) {
$content = $node->teaser;
}
//Check URL list settings
$_print_urls = _print_url_list_enabled($node, $format);
// Convert the a href elements
$pattern = '!<(a\s[^>]*?)>(.*?)()!is';
$content = preg_replace_callback($pattern, '_print_rewrite_urls', $content);
$print = _print_var_generator($node, $message, $cid);
$print['content'] = $content;
return $print;
}
?>
Comments
Comment #1
jcnventuraThanks for the suggestion. I've committed that change to git.
Comment #3
jcnventuraActually, there's a reason why it can't be set there.. It's useless there, as it will get overwritten by the node_load call.
Reverting the change fixes #1104290: build mode gets reset to 1 - should be 5