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.
CommentFileSizeAuthor
#4 simplenews_template.module.diff1.88 KBbtsukuda

Comments

tschewe’s picture

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!

IvanSandpile’s picture

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.

navs’s picture

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

btsukuda’s picture

StatusFileSize
new1.88 KB

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:

function _simplenews_template_theme_simplenews_newsletter_body($body, $title, $language) {
  return $body;
}

to:

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:

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

to:

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):

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:

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

to:

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.

kenorb’s picture