No Content in Newsletter

mRs- - January 3, 2009 - 11:36
Project:Simplenews Template
Version:6.x-1.0-beta1
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Description

I have no content in my newsletters!

The only thing i get is this warning message.

please help me!

* warning: Missing argument 3 for _simplenews_template_theme_simplenews_newsletter_body() in /www/htdocs/v088056/gpd/sites/all/modules/simplenews_template/simplenews_template.module on line 370.
* recoverable fatal error: Object of class stdClass could not be converted to string in /www/htdocs/v088056/gpd/sites/all/modules/simplenews/simplenews.module on line 1583.

#1

tschewe - January 3, 2009 - 21:17

I received the first warning with the same problem and the missing argument is $language.

I went back to SimpleNews to see if I could configure a language but now the SimpleNews configuration page is displaying nothing at all. I tried increasing the memory allowed to PHP in /etc/php.ini which solved this problem in another instance but even going to 64 MB didn't help here.

Damn! Just when I actually installed the newest version of SimpleNews and actually had it doing something useful!

#2

IvanSandpile - January 9, 2009 - 00:30

I got the same error. It disappeared when I set a default value in the PHP code for language:

function _simplenews_template_theme_simplenews_newsletter_body($body, $title, $language='EN') {

Simplenews worked fine, but when I added the template module, the header and footer appeared, but where the email body should have gone, it printed out "Object".

The log reported this error:

recoverable fatal error: Object of class stdClass could not be converted to string in /var/www/drupal/modules/simplenews/simplenews.module on line 1555.

I can still see all of the admin area for simplenews / templates, it just doesn't format the email content.

#3

navs - January 9, 2009 - 09:47

I'm getting the exact same error. When I added the 'EN' bit as suggested, that error line went away, still leaving the second problem. Is this the best newsletter module available for 6.x?

Navs

#4

btsukuda - January 12, 2009 - 19:54

I was having the same issue with no content showing up in (test) emails.

Attached is a diff of changes I made to simplenews_template.module to get it working for me.

First I changed:

<?php
function _simplenews_template_theme_simplenews_newsletter_body($body, $title, $language) {
  return
$body;
}
?>

to:
<?php
function _simplenews_template_theme_simplenews_newsletter_body($node, $language) {
  return
drupal_render($node->content);
}
?>

This function's variables weren't correct as per simplenews' hook_theme function. I am returning a rendered version of $node->content rather than just $node->content['body']['#value'] since the node's content might be more than just the body. This might be the wrong thing to do, since I can't actually recall checking if there was already a rendered version of the content available in the node object...

Next I changed this:

<?php
function simplenews_template_mail_alter(&$message) {
 
$function = "_simplenews_template_mail_alter_{$message['id']}";
  if (
function_exists($function)) {
   
$function($message);
  }
}
?>

to:
<?php
function simplenews_template_mail_alter(&$message) {
  static
$processed;
 
 
$function = "_simplenews_template_mail_alter_{$message['id']}";
  if (
function_exists($function)) {
   
$function($message);
  }
  else if (!
$processed) {
   
_simplenews_template_mail_alter_simplenews_node($message);
   
$processed = TRUE;
  }
}
?>

It looks like this is a hook to allow templating of newsletters based on the id of the newsletter so I didn't want to mess around with that. However, the function "_simplenews_template_mail_alter_simplenews_node" wasn't being called since there was no function of _simplenews_template_mail_alter_{simplenews_test} available. The $processed variable was added since _simplenews_template_mail_alter_simplenews_node() was being called twice for reason, and the second time the script would fail due to an empty $message being passed.

Looking at this now I'm thinking that this could also work without the need for the $processed variable (quick test, and it does):

<?php
function simplenews_template_mail_alter(&$message) { 
 
$function = "_simplenews_template_mail_alter_{$message['id']}";
  if (
function_exists($function)) {
   
$function($message);
  }
  else if (!empty(
$message)) {
   
_simplenews_template_mail_alter_simplenews_node($message);
  }
}
?>

Last, I changed this:

<?php
function _simplenews_template_mail_alter_simplenews_node(&$message) {
 
// Setup newsletter data
 
$tid = reset($message['params']['context']['account']->tids);
?>

to:
<?php
function _simplenews_template_mail_alter_simplenews_node(&$message) { 
 
// Setup newsletter data
 
 
if (!empty($message['params']['context']['account']->tids)) {
   
$tid = reset($message['params']['context']['account']->tids);
  }
  else {
   
$tid = $message['params']['context']['newsletter']->tid;
  }
?>

While I was debugging, I noticed that $message['params']['context']['account']->tids was an empty array while the term id was in $message['params']['context']['newsletter']->tid. I assume there was a good reason for getting the $tid from the account object so I left that in.

So far things seem to be working, but I haven't tested thoroughly, so some take some caution with these changes.

AttachmentSize
simplenews_template.module.diff 1.88 KB
 
 

Drupal is a registered trademark of Dries Buytaert.