when using the current dev versions of token and simplenews, I get the following error upon sending out a simplenews-newsletter:
User warning: Attempting to perform token replacement for token type simplenews-subscriber without required data in token_tokens() (line 791 of /var/www/www.iprhelpdesk.eu/htdocs/sites/all/modules/token/token.tokens.inc).

I cannot tell why he has a problem here because I do not use any tokens in the newsletter body, the only token is the newsletter-title which is used as a subject (afaik this is even a built-in token, independant of the token module).

Mails are sent out without error, but the log gets messed up with this warning message.

Comments

dave reid’s picture

Project: Token » Simplenews
Component: Miscellaneous » Code

This is a problem with the simplenews token API usage. This warning indicates you have a token in simplenews_token_info() that has a property 'needs-data' => 'something' and the token API expects token replacement to have $data['something'].

So in this case:

function simplenews_token_info() {
  $types['simplenews-subscriber'] = array(
    'name' => t('Simplenews subscriber'),
    'description' => t('@todo .'),
    'needs-data' => 'simplenews-subscriber',
  );
  $types['simplenews-newsletter'] = array(
    'name' => t('Simplenews newsletter'),
    'description' => t('@todo .'),
    'needs-data' => 'simplenews-newsletter',
  );
  $types['simplenews-category'] = array(
    'name' => t('Simplenews newsletter category'),
    'description' => t('@todo .'),
    'needs-data' => 'simplenews-category',
  );
...
}

function simplenews_tokens($type, $tokens, $data = array(), $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);

  switch ($type) {
    case 'simplenews-subscriber':
      $account = $data['account']; // not using $data['simplenews-subscriber'] - the 'needs-data' value should be 'account'
      $category = $data['category'];
      ...
    case 'simplenews-newsletter':
      $node = $data['node']; // not using $data['simplenews-newsletter'] - the 'needs-data' value should be 'node'
      ...
    case 'simplenews-category':
      $category = $data['category']; // not using $data['simplenews-category'] - the 'needs-data' value should be 'category'
      ...
}
dave reid’s picture

Also the simplenews-newsletter and its 'url' token seem to be needlessly duplicating the [node:url] token. I would suggest removing it completely.

simon georges’s picture

@Dave Reid, thanks for the detailed explanation, we will take care of it.

zauberertz’s picture

subsribe, can I help in some way?

kifuzzy’s picture

Priority: Normal » Critical

hi,

i have the same problem..

•User warning: Attempting to perform token replacement for token type simplenews-category without required data in token_tokens() (Zeile 791 von blank/sites/all/modules/token/token.tokens.inc).

•User warning: Attempting to perform token replacement for token type simplenews-subscriber without required data in token_tokens() (Zeile 791 von blank/sites/all/modules/token/token.tokens.inc).

•User warning: Attempting to perform token replacement for token type simplenews-category without required data in token_tokens() (Zeile 791 von blank/sites/all/modules/token/token.tokens.inc).

•Email not send.

in the file token.....inc:

 // If $type is a token type, $data[$type] is empty but $data[$entity_type] is
  // not, re-run token replacements.
  if (empty($data[$type]) && ($entity_type = token_get_entity_mapping('token', $type)) && $entity_type != $type && !empty($data[$entity_type]) && empty($options['recursive'])) {
    $data[$type] = $data[$entity_type];
    $options['recursive'] = TRUE;
    $replacements += module_invoke_all('tokens', $type, $tokens, $data, $options);
  }

  // If the token type specifics a 'needs-data' value, and the value is not
  // present in $data, then throw an error.
  $type_info = token_get_info($type);
  if (!empty($type_info['needs-data']) && !isset($data[$type_info['needs-data']])) {
trigger_error(t('Attempting to perform token replacement for token type %type without required data', array('%type' => $type)), E_USER_WARNING);
  }

  return $replacements;

so ... "if empty" ( its empty) ... it performs the message. and break sending emails.

test mails outgoing to recipient(s), testing the smtp - settings.
drupal - syslog says, a outgoing message is performing.
drupal syslog says, mail could not be send: Error (nothing else)

the text below is displaying for subscribers
currently on one of my drupal-test-installation-online-sites
.. "developing / test areas" for me before take some
on a "production site".

... i become more and more desperate... how can is solve
this that it works??

please, can someone help me?

p.s.:
.. i am not a coder...

edit:
using drupal 7.4
updated moduls (token, ..)
rules and entity api cause tested and will test "drupal for facebook"(now, its a .. facebook social.. modul)
phpmailer / mime mail (mailsystem) / simplenews

several versions since i was starting to find a way that it works.. for anonymous subscribers or others
using the form where they have to fill out the fied with their email-adress)

simon georges’s picture

@zauberetz, if you have some time to code the patch, don't hesitate to do it, I'll be happy to commit it !

pitxels’s picture

Is there any workaround before patching?
thanks

mangelp’s picture

StatusFileSize
new905 bytes

Following what Dave said in #1 seems that the patch is pretty trivial. I've patched the latest dev revision and attached it.

damiandab’s picture

cool , thanks for the patch

simon georges’s picture

Status: Active » Needs work

If you look at the "simplenews-subscriber" part, the code needs two kinds of data, first the account, then the category.
Anyway, thanks for the patch, it's a first step, I'll commit it a bit later, at least two out of three will then work.

simon georges’s picture

Ok, first step committed, let's work on having everything working.

berdir’s picture

StatusFileSize
new6.32 KB

The attached patch does some further cleanups:

- Removing newsletter tokens is tricky, because they're used all over the place and we don't want to just drop support for them. Instead, I added a DEPRECATED use X instead in the token description.
- Add correct token types to all token trees and contexts, including node.
- Added descriptions for our token types, this fixes #1316112: Status Report Token Required Information Missing
- newsletter category tokens are a duplicates of taxonomy terms as well but this is not as clear for users as it is for nodes I think. we also have additional info there, for which we could add tokens later on (stuff like mail format, from address, and more). So I kept that but added a term token which allows to use all taxonomy term tokens.
- This also re-implements token replacements on viewing the node directly.
- Updated some other descriptions.

berdir’s picture

Priority: Critical » Major
Status: Needs work » Needs review
StatusFileSize
new6.31 KB

Fixed Implementents typo...

miro_dietiker’s picture

Status: Needs review » Needs work

Discussed with Berdir:
Current release is alpha (only). Also it's the first 7.x release. So no guarantee for interface stability. Thus we decide to change token structures by intention to follow our clean naming. No deprecated notes needed.. Possibly add an upgrade note.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new10.08 KB

Ok, the updated patch removes newsletter tokens and adds a simple update function with a message mention this removal.

As Miro said, we're officially still in alpha so it's now or never, at least for 7.x-1.x.

Status: Needs review » Needs work

The last submitted patch, fix_tokens3.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new10.08 KB

Fixed a typo (simplenews_subscriber vs. simplenews-subscriber).

Status: Needs review » Needs work

The last submitted patch, fix_tokens4.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new11.49 KB

This one should be good.

miro_dietiker’s picture

Looks pretty fine.

BTW: How about the token UI ajax patch that you where working on recently? Did it get committed?

berdir’s picture

Status: Needs review » Fixed

Ok, commited (Trying to get as much as possible commited before doing another alpha).

What I worked on re. the token browser isn't really a solution, just a workaround. I just allowed lazy-loading of the (still the whole) token tree through ajax. That's just moving the processing out of the main page load. What the token browser actually needs is partial loading through ajax when you expand the tree. This is not a trivial thing to do I fear...

Status: Fixed » Closed (fixed)

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