Simplenews is now dependant on Token to do it's token replacement yet simplenews_template beta-3 still looks for the old custom token replacement function in simplenews and throws an error when it doesn't find it. The missing function is "simplenews_mail_tokens".

This is only applicable to the latest code in Simplenews but I guess it will probably be released soon as it's been in there for a while.

I've included a patch but it needs a bit of work as it's not doing the token replacement correctly, the third argument to token_replace is probably insufficient. I don't want to do a node_load in there though as it'll start to eat up memory so any suggestions welcome. This is fine for my purposes as I don't need to use tokens in the header or footer anyway.

117,118c117
<   $variables = simplenews_mail_tokens($user, $message['params']['context'], $language);
<   
---
>     
122c121
<   $header = strtr($header, $variables);
---
>   $header = token_replace($header, 'simplenews', array('node' => $node));
128c127
<   $footer = strtr($footer, $variables);
---
>   $footer = token_replace($footer, 'simplenews', array('node' => $node));
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

roball’s picture

Title: Fatal error with simplenews HEAD (token) » Fatal error with Simplenews 6.x-2.x: undefined function simplenews_mail_tokens()
Priority: Normal » Critical
FileSize
1.4 KB

The workaround by johngriffin is attached as a patch file, so people can apply it easier by doing

cd simplenews_template
wget "http://drupal.org/files/issues/simplenews_template.640740.simplenews_6.x-2.x.patch"
patch -p0 < simplenews_template.640740.simplenews_6.x-2.x.patch

Successfully tested, with the limitations pointed out above.

franz’s picture

It should be better then to use function_exists('simplenews_mail_tokens'), so it won't break compatibility.
Anyone willing to test this to see if it really tokenizes?

Also converted the patch to unix format...

Amstercad’s picture

Title: Still using function simplenews_mail_tokens() instead of token module » Fatal error with Simplenews 6.x-2.x: undefined function simplenews_mail_tokens()
Status: Fixed » Active

I had this same problem earlier, and google brought me to this page. Since someone checked in a CVS version for simplenews around Jan 1, I tried that, but the problem didn't go away. Then I applied this patch, and I am pleased to reply the problem went away. Thanks folks.

peterpoe’s picture

Status: Active » Reviewed & tested by the community

Confirming that the patch fixes the problem.

Amarjit’s picture

Confirm first patch also works.

franz’s picture

Title: Fatal error with Simplenews 6.x-2.x: undefined function simplenews_mail_tokens() » Still using function simplenews_mail_tokens() instead of token module
Status: Reviewed & tested by the community » Fixed

Improved title. BTW, hadn't noticed the version was wrong on it.

I've added the dependency to the .info and applied the patch.

Thanks for the work!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

muschpusch’s picture

Status: Closed (fixed) » Reviewed & tested by the community

please commit the patch...

muschpusch’s picture

Status: Reviewed & tested by the community » Fixed

sorry this was already committed to the current dev release

tallsimon’s picture

thank you for fixing this :-)

Title: Fatal error with Simplenews 6.x-2.x: undefined function simplenews_mail_tokens() » Still using function simplenews_mail_tokens() instead of token module
Status: Active » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.