The [node-content] token provided by the Content Notifications module seems to be interfering with the rendering of nodes "live" on site.
A theme with a node.tpl.php that renders node content "field by field" and includes a call to print $node->content['body']['#value'] would normally output only the HTML for the body field. However, with the Content Notifications module enabled, this call produces the same output as a call to print $content (fully rendered node content including all CCK fields as per display settings).
When combined with various calls to print CCK fields what results is a big mess with many fields outputted twice.
Commenting out the lines in notifications_content.module that define the [node-content] token fixes the problem - as per the sample below:
notifications_content.module @ line 907 ...
function notifications_content_token_list($type = 'all') {
$tokens = array();
if ($type == 'node' || $type == 'all') {
$tokens['node']['node-teaser'] = t('The node teaser.');
$tokens['node']['node-body'] = t('The node body.');
//$tokens['node']['node-content'] = t('The fully rendered node content.');
... etc
notifications_content.module @ line 927 ...
function notifications_content_token_values($type, $object = NULL, $options = array()) {
switch ($type) {
case 'node':
if ($node = $object) {
$values['node-teaser'] = !empty($node->teaser) ? check_markup($node->teaser, $node->format, FALSE) : '';
$values['node-body'] = !empty($node->body) ? check_markup($node->body, $node->format, FALSE) : '';
$values['node-url'] = url('node/'. $node->nid, array('absolute' => TRUE));
$values['node-teaser-raw'] = !empty($node->teaser) ? $node->teaser : '';
$values['node-body-raw'] = !empty($node->body) ? $node->body : '';
// Fully rendered node content
//$node = node_build_content($node);
//$values['node-content'] = drupal_render($node->content);
... etc
I'm not a drupal guru, but I suspect that the call to node_build_content is somehow replacing the "cached" copy of the node used for the lifetime of the page request, and this "mangled" node is being re-used by the page output?
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | notifications_content-node-content-rendered-twice-1.patch | 846 bytes | sutharsan |
Comments
Comment #1
sutharsan commentedThis problem is caused by
node->contentbeing rendered twice (drupal_render()function). The first time for the token, the second time for the node template. The node is passed by reference tonotifications_content_token_values(). In php5 all objects are passed by reference!!The attached patch solves this problem. Since
drupal_render() is used frequently in the Notifications module, the complete module should be checked for similar situations.Comment #2
TheDanScott commentedThanks Suthsaran!
And thanks also for the explanation of what was going wrong - most helpful to those of us still learning the ins and outs of what goes on in the huge mass of Drupal code :)
Cheers
Daniel
Comment #3
sutharsan commented@TheSchmuck, are you able to test this code? Then we can move the status to 'reviewed and tested by the community' and hopefully this will be included in the module.
Comment #4
fredklopper commented@Sutharsan I've tested it and it works like a charm.
Thanks!
Comment #5
CraigBertrand commentedThis also worked for me. I was having a problem where all my node content in certain content types were mysteriously disappearing.
Changed the line of code and it is back now.
This should be committed.
Comment #6
jim kirkpatrick commentedConfirmed both the issue and the workaround from #1. Had my own issues caused by this over at #1350586: Disapearing node content; #childen empty on elements within fieldsets...
And upping the priority due to consensus and because this bug has the potential (proven for me) to ruin the custom theme/tpl.php functions by dropping the rendered output of many parts of a node's variables/body etc across the whole site.
Comment #7
danepowell commentedhttp://drupalcode.org/project/notifications.git/commit/58c2b28