Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I want to add a new newsletter category after a new node is saved. I've created a rule that adds a new term, but the category is not created...
Is it possible to create a new category through rules module? Maybe with a bit of PHP?
Is there any API function to solve this issue?
Thanks!
Comments
Comment #1
strainyy CreditAttribution: strainyy commentedAny luck with this? I'd like to achieve the same thing...
Comment #2
strainyy CreditAttribution: strainyy commentedI've managed to create a new Newsletter whenever a user adds a taxonomy term of a certain type. Maybe this will help you work out how to do it with nodes.
Within your rule configuration, create an action of the type "Execute Custom PHP Code".
tags as they are just for formatting this comment.
Enter the following code, but omit the
And to delete the category when a certain taxonomy term is deleted create a new rule that reacts to the taxonomy term deleted event. Again, create an action of the type "Execute Custom PHP code". Simply place the following code in the text area:
Once again, remember to delete the openning and closing PHP tags as they are just for formatting in this comment.
Hopefully this helps anyone having the same sort of SimpleNews automation issues.
Comment #3
olak CreditAttribution: olak commentedi have a similar usecase. when a node of certain type is created, i'd like a new newsletter category of the same name. as i understand, creating a taxonomy term of "newsletter" doesnt create a newsletter. you have to add it in admin/config/services/simplenews/add
and i dont see such an action in simplenews rules. @strainyy , can you post your whole rule (export it first)? it would be very helpful, to see how you implemented it.
Comment #4
neoxavier CreditAttribution: neoxavier commentedActually you dont need simplenews rules to do this.
In rules action, you need to pick create "new entity" then pick "simplenews Newsletter" as entity type
Note: in version 2 simplenews use entity rather than taxonomy category. in version 2 there is no newsletter category
Comment #5
techn0guy CreditAttribution: techn0guy commented@neoxavier
I don't see this option under the new entity field, am I missing something here? Also when I try using the custom PHP code, the name of the newsletter category doesn't populate... when looking into the module code it seems that a taxonomy term needs to be create too, but I can't get that to work
Comment #6
neoxavier CreditAttribution: neoxavier commented@techn0guy are you using simplenews version 2, because the version 1 uses taxonomy category and version 2 uses entity
Comment #7
Sebastian HagensThis is how I managed it to get a working solution (version 7.x-1.1) to create a Newsletter category on a node save event:
Before the action where the PHP code is executed from #2 I've added these actions:
1. Fetch new entity (entity type: Taxonomy term)
2. Save entity (force save checked on true)
The taxonomy term name and category name are the same as the provided node:title value.
The export of my rule: