Thursday, Sep 27, 2012
Slides
Overview
- What is the Rules module?
- What are Events, Conditions and Actions?
- Using the Data Selector
- Components and Scheduling
- Looping Actions
- Real world examples
- Using Rules to change the article node title to include the node id?
- Using Rules to email the administrators when a new comment is created?
- Using Rules with Views Bulk Operations to unpublish nodes?
What is the rules module?
- Rules consist of Events, Conditions and Actions
- Simply it looks for an event
- When that event happens (under certain conditions)
- It fires off an action
What is an event?
- Events are linked to things happening on your site
- Comment (viewed, created, deleted)
- Node (viewed, updated, created)
- System (cron, bootstrapped)
- Taxonomy (create term/vocabulary)
- User (log in/out, created, updated)
- Extended by other modules (Profile, Feeds etc)
What is a condition?
- Conditions check what the specifications of the event are
- Data (comparison, empty)
- Entity (field exists)
- Content (load all fields)
- Path (check path)
- User (check role)
What is an action?
- Do something
- Data (add variable, set value)
- Entity (create entity, fetch entity)
- Node (publish content, make sticky)
- System (redirect, send email, set message)
- User (add role)
The data selector
- Choosing the data you want to interact with
- Direct input mode
- Using tokens
- [site:current-date]
- [site:current-user]
- [node:title]
- [node:nid]
- Data selection mode – Interactive browse through tokens
What are components?
- A set of rules/actions
- To be used either by Rules or other modules
- Views Bulk Operations
- Drupal Commerce
What is scheduling rules?
- Set your rules to be activated based on time
- Set nodes to be unpublished 2 weeks after publishing
- Disallow comments 1 year after publish date
What are looping actions?
- Do the action for multiple items
- Send email to all users
- Unpublish referenced items
Real World Examples
Using Rules to change the article node title to include the node id?
- Go to Rules (Administration > Workflow > Rules)
-
- Name it
- Event: Before Saving Content
-
- Content is of Type
- Value = Article
-
- Set a data value
- Data - “node:title”
- Value - “node:title – node:nid”
- Save
- Go to Rules (Administration > Workflow > Rules)
-
- Name it
- Event: After a comment is saved
- (+ Add Condition) Not needed for this rule! Fool!
-
- Send an email to all users of a role
- Select role - “administrator”
- Values – Subject, Message (can include tokens)
- Save
Using Rules with Views Bulk Operations to unpublish nodes?
- Go to Rules (Administration > Workflow > Rules)
- Select components
-
- Rule set (or action if no conditions needed)
- Name it
- Data type – Node
- Label, and machine name
-
- Name rule - “Unpublish node”
-
- Add condition (if required)
-
- Unpublish Content
- Data: node
- Go to your view (or create a new one)
- Add Bulk operations: content
- Choose the required component “Unpublish nodes”
- Save
- It will then use the rule on all the ids you send to it!
Can Rules make me a sandwich? … Maybe?