I have some additional fields managed in admin/config/people/simplenews/settings/subscriber that I'd like to use in the newsletter node via token. It is basically the full name of the person. But I can't really see that field being available in the tokens.

Am I missing something?

CommentFileSizeAuthor
#10 simplenews.field-tokens.3088574-10.patch536 bytesadamps

Comments

Nchase created an issue. See original summary.

nchase’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

same for 8.x-2.x-dev. There is no access to the additional fields created at admin/config/people/simplenews/settings/subscriber that can be filled by Anonymous subscribers.

vistree’s picture

Yes, I am also having this problem. How to use extra user fields in Newsletter text fields? Would be absolutly cool to be able to use them ;-)

nchase’s picture

Use case for me is: Personalizing the newsletter with for example the name of the anonymous subscriber.

vistree’s picture

@Nchase: same for me ;-)

adamps’s picture

Title: How to get access to additional subscriber fields in the newsletter node via token » Subscriber missing tokens for fields
Category: Support request » Bug report

Thanks for the report - it's a bug.

The problem is that the entity type in Subscriber.php is simplenews_subscriber but the token type in simplenews.tokens is simplenews-subscriber - one with underscore and one with dash. This means that field_token_info_alter() doesn't add the field tokens. The fix is to add code as below to Subscriber.php at the bottom of the comment @ContentEntityType.

 *   token_type = "simplenews-subscriber"

Same problem for newsletter.

nchase’s picture

adding it like:

 *     "delete-form" = "/admin/people/simplenews/delete/{simplenews_subscriber}",
 *   }
 * )
 *   token_type = "simplenews-subscriber"
 */

doesn't change a thing. The tokens are not available.

adamps’s picture

The comments are effectively code so it has to be done exactly right, like this. Hopefully someone can make a patch soon - the hard work is done which was to figure the cause.


 *   links = {
 *     "edit-form" = "/admin/people/simplenews/edit/{simplenews_subscriber}",
 *     "delete-form" = "/admin/people/simplenews/delete/{simplenews_subscriber}",
 *   },
 *   token_type = "simplenews-subscriber"
 * )

nchase’s picture

AdamPS, thanks for pointing this out. It works perfectly!

adamps’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new536 bytes
adamps’s picture

Issue tags: -Needs tests +Plan to commit

This is a simple one-line change that fixes a problem hit twice recently. It's the sort of change that feels not very easily accidentally broken in future. So I think it is worth committing without tests.

  • AdamPS committed 0bed6e3 on 8.x-2.x
    Issue #3088574 by AdamPS: Subscriber missing tokens for fields
    
adamps’s picture

Status: Needs review » Fixed
Issue tags: -Plan to commit

Status: Fixed » Closed (fixed)

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

cuman’s picture

If token is empty it have to be hide
but now it inserts in the newsletter as is [simplenews-subscriber:field_first_name:value]
Token_filter modul lets hide empty token, but token_filter processes token before newsletter sending