Upload
truongdung
View
233
Download
0
Embed Size (px)
Citation preview
Rulesin Drupal 7events > conditions > actions
4/8/12
Wednesday, April 11, 2012
You
★ Where are you at on the Drupal learning curve?
photo credit: damnengine http://damnengine.deviantart.com/art/Road-58172753
Wednesday, April 11, 2012
What We’ll Learn
• The problem(s) the Rules module solves• Background on Entities in Drupal 7• Rules concepts: Events, Conditions,
Actions• How to configure Rules• How to extend Rules
Wednesday, April 11, 2012
Rules
• In a nutshell, an API and UI for defining and conditionally executing actions within Drupal.
Wednesday, April 11, 2012
Prerequisite Knowledge
• Entities• Added in Drupal 7• Entities are the new nodes - first class
citizens• Abstraction for content
Wednesday, April 11, 2012
Entities, for example...
• Nodes
• Comments
• Users
• Taxonomy Terms
• ... and Rules configurations ...
photo credit: http://commons.wikimedia.org/wiki/File:Starry_night_at_Mount_Everest.jpgBy Matt Wier (Own work) [CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)],
via Wikimedia CommonsWednesday, April 11, 2012
Purpose of Entities
• Provide a common, consistent programmatic API for content “entities.”
Wednesday, April 11, 2012
As a result...
• All entities are fieldable...(Remember, they’re the new nodes.)
• Users, nodes, terms, comments, etc.
Wednesday, April 11, 2012
Extending Core Entities
• Drupal Core’s entity API is incomplete.
• Enter: Entity API for a full CRUD wrapper. https://drupal.org/project/entity
Wednesday, April 11, 2012
Prerequisites for Rules
• Entity API - extends API
(We’re talking Drupal 7.)
Wednesday, April 11, 2012
Why Does Entities Matter?
• Entities in Drupal 7 + Rules is like when CCK and Views arrived on the scene together.
• A game-changing moment in Drupal.
Wednesday, April 11, 2012
So what is Rules?
• Successor to Rules 1, and Workflow NG
• Rules is to Trigger moduleASSwiss Army Knife is to Steak Knife
photo credit: http://commons.wikimedia.org/wiki/File%3AGears_in_Museu_da_Electricidade.jpgBy gcardinal from Norway (Gears of power) [CC-BY-2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons
Wednesday, April 11, 2012
Enable Rules
• Download Rules modulehttp://drupal.org/project/rules
• Enable: Rules, Rules API, and optionally, Rules Scheduler
Wednesday, April 11, 2012
Configuration
• Update settings, and add rules configurations viaadmin > configurations > workflow: Rules
Wednesday, April 11, 2012
Turn on Debugging
• See under settings. Check to show debugging information “always” during development.
Wednesday, April 11, 2012
Configuring Rules
• A rule configuration consists of• Events• Conditions• Actions
Wednesday, April 11, 2012
Event examples
• A node is viewed• A node has been / is about to be saved• Cron is running• A system log message is created
Wednesday, April 11, 2012
Condition examples
• User has role(s)• Field content contains “x”• Field A is greater than Field B• List contains item (e.g. tags contain term Z)
• Node is of type• Entity is of type (bundle)• Custom PHP code evaluation
Wednesday, April 11, 2012
Action examples
• Set a Data Variable• Publish/Unpublish, Sticky/Unsticky• Display System Message, Send Email• Add/Remove User Role• Alter paths• Create Entities• Custom PHP
Wednesday, April 11, 2012
More Concepts
• Conditional OR and AND Groups• No Conditional Branching for Actions• Lists (terms, multi-value fields...)• Loops (process lists)• Components (re-usable config sets)• Data Selection
Wednesday, April 11, 2012
Data Selection UI
• Entities + Tokens enables the Data Selection API, which is at the heart of Rules’ awesomeness.
• Let’s see it in action...
Wednesday, April 11, 2012
Demo
• Let’s make a rules configuration related to cuss words.
Wednesday, April 11, 2012
Integration with
• Views Bulk Operations - execute Rules components on VBO lists
• Flag - execute Rules when an entity is flagged
Wednesday, April 11, 2012
Rules Link Module
• Trigger Rules with custom links• http://drupal.org/project/rules_link
Wednesday, April 11, 2012
Extend Rules by Providing your own
• Events• Conditions• Actions• Entities and entity properties
Wednesday, April 11, 2012
Further Readingand Screencasts
• Rules Documentation• http://drupal.org/node/298476
• Rules Handbook• http://drupal.org/node/1299990
• Rules Screencasts• Site Building/Framework
http://dev.nodeone.se/node/984• Development/API
http://dev.nodeone.se/en/coding-for-rules-2
Wednesday, April 11, 2012
Workbench Module
• For a turnkey workflow and content moderation module, see Workbench:http://drupal.org/project/workbench
Wednesday, April 11, 2012
Workbench Features
• Workbench Access: Provide access to content based on menu or taxonomy hierarchies.
• Workbench Moderation: Move content through publishing states like “draft,” “moderation,” “published.”
• Workbench Files and Workbench Media: Integration and workflows for files and media.
Wednesday, April 11, 2012
What We Learned
• The problem(s) the Rules module solves• Background on Entities in Drupal 7• Rules concepts: Events, Conditions,
Actions• How to configure Rules (featuring the
Data Selection UI)• How to extend Rules
Wednesday, April 11, 2012