29
Rules in Drupal 7 events > conditions > actions [email protected] mlsamuelson.com 4/8/12 Wednesday, April 11, 2012

Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions [email protected] mlsamuelson.com

Embed Size (px)

Citation preview

Page 1: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Rulesin Drupal 7events > conditions > actions

[email protected]

4/8/12

Wednesday, April 11, 2012

Page 2: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

You

★ Where are you at on the Drupal learning curve?

photo credit: damnengine http://damnengine.deviantart.com/art/Road-58172753

Wednesday, April 11, 2012

Page 3: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 4: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Rules

• In a nutshell, an API and UI for defining and conditionally executing actions within Drupal.

Wednesday, April 11, 2012

Page 5: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Prerequisite Knowledge

• Entities• Added in Drupal 7• Entities are the new nodes - first class

citizens• Abstraction for content

Wednesday, April 11, 2012

Page 6: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 7: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Purpose of Entities

• Provide a common, consistent programmatic API for content “entities.”

Wednesday, April 11, 2012

Page 8: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

As a result...

• All entities are fieldable...(Remember, they’re the new nodes.)

• Users, nodes, terms, comments, etc.

Wednesday, April 11, 2012

Page 9: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 10: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Prerequisites for Rules

• Entity API - extends API

(We’re talking Drupal 7.)

Wednesday, April 11, 2012

Page 11: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 12: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 13: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Enable Rules

• Download Rules modulehttp://drupal.org/project/rules

• Enable: Rules, Rules API, and optionally, Rules Scheduler

Wednesday, April 11, 2012

Page 14: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Configuration

• Update settings, and add rules configurations viaadmin > configurations > workflow: Rules

Wednesday, April 11, 2012

Page 15: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Turn on Debugging

• See under settings. Check to show debugging information “always” during development.

Wednesday, April 11, 2012

Page 16: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Configuring Rules

• A rule configuration consists of• Events• Conditions• Actions

Wednesday, April 11, 2012

Page 17: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 18: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 19: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 20: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 21: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 22: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Demo

• Let’s make a rules configuration related to cuss words.

Wednesday, April 11, 2012

Page 23: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Integration with

• Views Bulk Operations - execute Rules components on VBO lists

• Flag - execute Rules when an entity is flagged

Wednesday, April 11, 2012

Page 24: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Rules Link Module

• Trigger Rules with custom links• http://drupal.org/project/rules_link

Wednesday, April 11, 2012

Page 25: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Extend Rules by Providing your own

• Events• Conditions• Actions• Entities and entity properties

Wednesday, April 11, 2012

Page 26: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 27: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

Workbench Module

• For a turnkey workflow and content moderation module, see Workbench:http://drupal.org/project/workbench

Wednesday, April 11, 2012

Page 28: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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

Page 29: Rules in Drupal 7 - mlsamuelson.commlsamuelson.com/sites/default/files/rules-presentation-2012-04-11.pdf · Rules in Drupal 7 events > conditions > actions mlsamuel@asu.edu mlsamuelson.com

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