Using fields for setting evaluation time
This is documentation for Drupal 7, which is no longer supported. Learn more and find resources for Drupal 7 sites
Learn the Rules framework part 15: Using fields for setting evaluation time ### Notes Below
This screencast shows how to use fields when scheduling Rules components. In the example we are also using the Flag module, to allow people to sign up for reminder e-mails 24 hours before an event starts. The screencast covers:
Using flags to load user lists in Rules
Scheduing a rules component from a triggered rule
Some words about rescheduling the evaluation if the event date should change
Using conditions to make fields available in Rules configuration
Using a date field to set evaluation time
Adding an offset to the evaluation (-1 day)
Verifying the configuration by executing the action set manually
Note 1: It would have been smarter to use the "Before saving content" event for this rule – to make it act on both new nodes and updates of existing ones. If combined with a check to see that the event is in the future, you would actually have pretty good notification system!
Note 2: I managed to keep this screencast under ten minutes!
## Notes ##
The following steps are a 'transcript' of the video; attempting to use node:created field to determine publishing
- Rules Scheduler >> Component >> Action set
- Configure
- give name like "Publish for Schedule"
- Datatype: Node, Label: node, Machine name: node, Usage: parameter
- weight: 10, so it gets run after any other rules
- Select the action to add:
- set a data value
- node:status
- value = choose from dropdown
- Rules >> create new rule
- "Publish on Schedule"
- React on "after saving new content", or "Before saving content" (if you want to edit something later)
- Add condition
- data comparison
- node:created
- is greater than; now
- Add Action >> Unpublish
- Add Action >> Rules scheduler >> "Schedule component evaluation"
- Pick your component "Publish for Schedule"
- Scheduled Evaluation Date - enter `node:created` (OR choose offset or enter offset like +X days)
- Identifier: MUST BE UNIQUE, like "schedule publish for node [node:nid]" - using token for unique action per node
- Data selector = `node`
EXPORT // -----------------
/****** COMPONENT ******/
{ "rules_publish_for_schedule" : {
"LABEL" : "Publish for Schedule",
"PLUGIN" : "action set",
"TAGS" : [ "publish", "scheduling" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } },
"ACTION SET" : [ { "data_set" : { "data" : [ "node:status" ], "value" : "0" } } ]
}
}
/****** RULE ******/
{ "rules_schedule_publishing" : {
"LABEL" : "Schedule Publishing",
"PLUGIN" : "reaction rule",
"WEIGHT" : "10",
"TAGS" : [ "publish", "scheduling" ],
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : [ "node_presave" ],
"IF" : [
{ "OR" : [
{ "data_is" : { "data" : [ "node:changed" ], "op" : "\u003e", "value" : "now" } },
{ "data_is" : { "data" : [ "node:created" ], "op" : "\u003e", "value" : "now" } }
]
}
],
"DO" : [
{ "node_unpublish" : { "node" : [ "node" ] } },
{ "schedule" : {
"component" : "rules_publish_for_schedule",
"date" : [ "node:created" ],
"identifier" : "Scheduled publish for node [node:nid]",
"param_node" : [ "node" ]
}
}
]
}
}
------------------- // EXPORT
Review scheduled tasks (if Views module enabled) from Rules >> Schedule
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion