Community Documentation

How to create a newsletter containing existing content, using entity reference, rules and VBO

Last updated November 29, 2012. Created by gaele on March 21, 2012.
Edited by Rob C, authentictech. Log in to edit this page.

Use the recipe below to create a page, that will allow you to select existing nodes from a list and incorporate them in a Simplenews newsletter.

The page is based on a view. The selected nodes will be fed to a Rules component. This component will create a newsletter, and put the selected nodes in an entity reference field of the newsletter. The newsletter content type is configured to display the teasers of all referenced nodes.

Requirements

Entity reference

Add an entity reference field to the newsletter content type (Content types > Simplenews newsletter > Manage fields).

  • Field name: Articles (field_simplenews_articles)
  • Field type: Entity Reference
  • Widget: Inline entity form

Now click on the save button, on the next page set up the folling settings:

  • Inline Entity Form: Allow users to add existing nodes
  • Number of values: Unlimited
  • Target type: Node
  • Target bundles: Article (or whatever content type you would like to use)
  • Sort by: nid or created (or whatever field you would like to use)

Now go to Manage display, and set the field Articles to

  • Label: Hidden
  • Format: Rendered entity (Rendered as Teaser)

Rules

Create a Rules component (Configuration > Workflow > Rules > Components).

  • Name: Create newsletter
  • Variables: A List of node items, labeled Articles, used as input parameter
  • Actions:
    1. Create a new entity: type Node, content type Simplenews newsletter, title Newsletter
    2. Set a data value: selected data newsletter-created:field-simplenews-term, value: the newsletter category you would like to use
    3. Loop: data selector articles, current list item Article
      Inside the loop:
      1. Add an item to a list: list newsletter-created:field-simplenews-articles, item to add article
    4. Save entity: entity newsletter-created, Force saving immediately true
    5. Page redirect: URL [newsletter-created:url]

VBO

Create a view with a page display.

  • Format: table
  • Fields:
    1. Bulk operations: Content with Selected operations Create newsletter (rules_create_newsletter)
    2. Content: Title
  • Filter criteria:
    1. Content: Published (Yes)
    2. Content: Type (= Article)
  • Sort criteria: Content: Post date (desc)
  • Page settings / Access: Permission | Simplenews newsletter: Create new content

Inline entity form

Inline entity form is a module created for the commerce module, it's mostly used to add products to a product display, but it also works great for adding other nodes to a newsletter and offers a way to order the list that is created via the VBO view provided on this post.

Notes

  • You could add a hidden boolean field to the Article content type. The Rules component would set this to TRUE, and the view would filter on this field being FALSE. Thus the view would only show articles not yet published in a newsletter.
  • Using Rules Scheduler you could automatically create and send a newsletter containing all new articles from last week or month.
  • TODO: add a way to change the order of articles in a newsletter (using the Weight module or DraggableViews) Done, see Inline Entity Form

(With help from darrenmothersele and trackleft)

AttachmentSize
create-newsletter-rules-component.txt1.09 KB
create-newsletter-view.txt10.32 KB

Comments

Great tutorial!

Great tutorial ! Thanks so much!
Is it possible to make it use a custom email theme?
What ever I do it seems impossible to make it use my custom email theme...

Cheers,

Can't create add list

Loop: data selector articles, current list item Article
Inside the loop:

Add an item to a list: list newsletter-created:field-simplenews-articles, item to add article

For some reason the data selector will not allow me to chose
"newsletter-created:field-simplenews-articles"
I get an error:
"The data type of the configured argument does not match the parameter's list requirement."

Any ideas as to why?

Found the reason

The entity reference field must be set to unlimited for add to lists to work.

Enity reference not showing in sent newletter

The above all works for creating the newsletter. However, the sent newsletter dose not contain the attached content created by entity reference. Any ideas?

Go to the "Manage display"

Go to the "Manage display" tab of the newsletter content type, and make sure the Articles field is set to "Rendered entity".

Do the selected articles show up in the newsletter on the site?
Do you use plain text or HTML for sending newsletters?

Yes all is done, But still not in email

Default Display, as well as all mail displays are set to "rendered entity"

All the articles do show on the newsletter page on the site. They just are not being mailed.

I am using html to send but I also tested plain text and still have the same result.

Thanks for your help. Any other suggestions?

Sorry, I cannot reproduce

Sorry, I cannot reproduce this on my system.
Do you have any custom theme templates that may be in the way?

I have just been having the

I have just been having the same problem.
Can you articles be viewed by anon users ?

It might be a permissions issue.
I changed the permissions for my articles to be viewed by anon users then it worked. (I am using the content access module on my site)

This is a very helpful

This is a very helpful tutorial. I am having the same problem though where it wont let me add the right field as the Add item to list action. It says:
Data selector newsletter-created:field-simplenews-articles for parameter list is invalid.

I do have the field set to unlimited - does it matter what the widget type is?

EDIT - I found an error in my setup and now this works as described

Just a side note: I think that rule "5. Page redirect: URL [newsletter-created:url]" is missing in the "create-newsletter-rules-component.txt" so dont forget to add this step manually after importing the rule component.

Thanks for that greate

Thanks for that greate tutorial, I got it working just with Entity reference ;D

The only problem I have is, that when i set the display "Rendered as..." to anything else then "teaser", I recieve a hole bunch of errors when sending the newsletter:

    Warning: DOMDocumentFragment::appendXML(): Entity: line 8: parser error : StartTag: invalid element name in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): //--> in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): ^ in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): Entity: line 8: parser error : Sequence ']]>' not allowed in content in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): //--> in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): ^ in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): Entity: line 8: parser error : Sequence ']]>' not allowed in content in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): //--> in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): ^ in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): Entity: line 8: parser error : internal error in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): //--> in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMDocumentFragment::appendXML(): ^ in filter_dom_serialize_escape_cdata_element() (Zeile 1111 von /srv/www/basti/modules/filter/filter.module).
    Warning: DOMNode::appendChild(): Document Fragment is empty in filter_dom_serialize_escape_cdata_element() (Zeile 1112 von /srv/www/basti/modules/filter/filter.module).

Any idea about that ?

Newsletter title

Hi, this is awesome!
However, one question... The newsletter created is always named "Newsletter". I added a token replacement pattern of [site:current-date] to the title, to distinguish it from other newsletters.

However, that token adds both date and time to the title. That won't work, because everyone will be receiving the newsletter at different times based on cron.

Is there any way to have it just be Newsletter and the current date (not the time)?

I can't seem to get it to use date styles/formats.

Anyone's help would be appreciated.

Elena

Another issue

I am rendering the full node output: Email: HTML instead of just the teaser, and I'm getting links for Edit, Delete and Manage Display, even though those links are not in the Email:HTML Display Screen for the Article Content Type that I'm exporting.

When I was sending the newsletter directly from the Article node itself instead of pulling it into the Newsletter node, I was not getting these links.

Elena

Everything works find except

Everything works find except the Edit and Delete link. I can't send the newsletter if those link are in it.

Did someone solved this problem?
How to get rid of the Edit and Delete links in the e-mail?

same problem

Ok....found it....Turn off contextual links in D7 (it is a core module)

hope it helps....it worked for me...

Why so complicated?

Ok, I'm totally lost. I'm trying to make a newsletter for a quite long time and so far, none of the modules I tried was good enough - one would think this should be simple, but it's not.

I was sure SimpleNews is the right way - it's the most popular tool for it, right? But no, I can't even find where's the button to send a test newsletter. Can't even follow this tutorial, as it's not precise enought (what component plugin? I couldn't find some of the things about created entity at all). And really, so much work for newsletter?

I would really love to make a simple daily newsletter which would list to user a list of new nodes of certain content type. I tried doing it my way, built a new View with all the things I need. Now, I would only need a way to send it as newsletter. Maybe Rules? But I don't have much experience in Rules - no idea on what event it should react. Can anyone help me, I'm really trying to get this done from few weeks already.

target type: node

This tutorial is exactly what I've been looking for, but I'm having one issue. There is not option for "Node" under "Target Type:" when I try to manage the fields on my newsletter node. I've found some others with the same problem, and they fixed it by reinstalling entityreference. Unfortunately, that didn't work for me. Can anyone make any suggestions?

Fantastic guide

Hi gaele
I am using this guide to create a newsletter for a new site, it works great!!
Now I have a doubt, on this site we have two types of content for include in the newsletter, I would like the user could use a different view to select contents from each content type.
What would be the best way to make this?

Page not found

Thank you for going through the effort to figure out the steps and reproducing them here in a tutorial.
I have followed the steps the best I could.

Rules 5. Page redirect: URL [newsletter-created:url] results in a "Page not found The requested page "/%5Bnewsletter-created%3Aurl%5D" could not be found."
So, I guess I'm leaving something out.

Any suggestions?

Check in Rules component in

Check in Rules component in the "save entity" action, if the checkbox "force record immediately" is well set.

For drupal 6?

I try to follow the instruction but i cant do it. In drupal 7 the fields change a lot!

Same problem here. D7 has

Same problem here. D7 has change a lot. Need new instruction plz.

Mailchimp - mcc module and vbo

I wanted this to work with mailchimp. So i did some research. You can use this guide in combination with mailchimp, mcc module (unstable but it works) and of course vbo. Just make your own content type instead of using the simplenews one, the rest is as described in this great tutorial.

Hope it helps some people...

I'm stuck too

Actions point 2 - the option just isn't there. I can't get the loop set up either.

Is there anyone who got it working who could provide more up-to-date instructions?

Hélène

make sure you don't miss this

make sure you don't miss this point:

Variables: A List of node items, labeled Articles, used as input parameter (you find this when you create your rule component). If you don't adds this you won't have access to it.

Parameter options

Create a new entity - got it
A List of node items - got it
labeled Articles - got it
input parameter - not one of the options.

Options are: Parameter, Parameter + Provided, Provided

which one is right?

One thing that threw me off is the newsletter-created: This is just the name given to the Action. In my case I went with what was already there which is entity-created.

Another thing that's really confusing is Action 2. You have to give it a value but I don't know what that should be. When you select -term, I assume it is referring to the taxonomy Newsletter. How does this fit with the end result? Will this entire setup be applicable only to that term?

Hélène

Column 'tid' cannot be null

I am getting the error "column 'tid' cannot be null: INSERT INTO {simplenews_newsletter}..." when try to execute the rule. I am using Drupal 7.19 / Simplenews - version 7x-1.0

Any thoughts what i might doing wrong?

R

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Site administrators
Level
Advanced

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.