rules for fools: the rules module

32

Upload: will-hall

Post on 05-Jul-2015

4.155 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Rules for Fools: The Rules Module
Page 2: Rules for Fools: The Rules Module

In 1972, a crack web development team was sent to prison by a military court for a module they didn't commit. These men promptly escaped from a maximum security stockade to the php underground. Today, still wanted by the community, they survive as soldiers of fortune.

If you have a problem, if no other module can help, and if you can understand it, maybe you can use...

Page 3: Rules for Fools: The Rules Module
Page 4: Rules for Fools: The Rules Module
Page 5: Rules for Fools: The Rules Module
Page 6: Rules for Fools: The Rules Module

Starring

Will Hallas

b.a. baracus

Tweet me, fool:@willhallonline

Page 7: Rules for Fools: The Rules Module

and

Will's cat Elizaas

“howling mad”Murdock

Miaow.

Page 8: Rules for Fools: The Rules Module

● What is the Rules module?● What are Events, Conditions and Actions?● Using the Data Selector● Components and Scheduling● Looping Actions● Real world examples (with BA and Murdock)● A tank building montage(!)

Rules for Fools

Page 9: Rules for Fools: The Rules Module

I love it when a rule

comes together

Page 10: Rules for Fools: 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 the rules module?

Page 11: Rules for Fools: The Rules Module

● 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 an event?

Page 12: Rules for Fools: The Rules Module

● 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 a condition?

Page 13: Rules for Fools: The Rules Module

● 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)

What is an Action?

Page 14: Rules for Fools: The Rules Module

DrupalCausality

Page 15: Rules for Fools: The Rules Module

Because this EVENT happened,

under these conditions, this

action will take place.

Page 16: Rules for Fools: The Rules Module

● 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

The data selector

Page 17: Rules for Fools: The Rules Module

● A set of rules/actions● To be used either by Rules or other modules● Views Bulk Operations● Drupal Commerce

What are components?

Page 18: Rules for Fools: The Rules Module

● 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 is scheduling rules?

Page 19: Rules for Fools: The Rules Module

● Do the action for multiple items● Send email to all users● Unpublish referenced items

What are looping actions?

Page 20: Rules for Fools: The Rules Module

REAL World Exampleswith BA and Murdock

Hey. I don't use Rules yet.

Page 21: Rules for Fools: The Rules Module

Can I use Rules to change the article node title to

include the node id?

Page 22: Rules for Fools: The Rules Module

● Go to Rules (Administration > Workflow > Rules)

● + Add new rule

● Name it

● Event: Before Saving Content

● + Add Condition

● Content is of Type

● Value = Article

● + Add action

● Set a data value

● Data - “node:title”

● Value - “node:title – node:nid”

● Save

R.w.e with BA and Murdock 1

Page 23: Rules for Fools: The Rules Module

Can I use Rules to email theadministrator when a new

comment is created?

Page 24: Rules for Fools: The Rules Module

● Go to Rules (Administration > Workflow > Rules)

● + Add new rule

● Name it

● Event: After a comment is saved

● (+ Add Condition) Not needed for this rule! Fool!

● + Add action

● Send an email to all users of a role

● Select role - “administrator”

● Values – Subject, Message (can include tokens)

● Save

R.w.e with BA and Murdock 1

Page 25: Rules for Fools: The Rules Module

How can I use Rules with Views Bulk Operations to

unpublish nodes?

Page 26: Rules for Fools: The Rules Module

● Go to Rules (Administration > Workflow > Rules)

● Select components

● + Add new component

● Rule set (or action if no conditions needed)

● Name it

● Data type – Node

● Label, and machine name

● Continue...

R.w.e. - BA and Murdock 3a

Page 27: Rules for Fools: The Rules Module

● + Add rule

● Name rule - “Unpublish node”

● + Add condition (if required)

● + Add action

● Unpublish Content

● Data: node

R.w.e. - BA and Murdock 3b

Page 28: Rules for Fools: The Rules Module

● 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 id's you send to it!

R.w.e. - BA and Murdock 3c

Page 29: Rules for Fools: The Rules Module

Can Rules make me a sandwich?

Page 30: Rules for Fools: The Rules Module

Montage!

Page 31: Rules for Fools: The Rules Module

● What is the Rules module?● What are Events, Conditions and Actions?● Using the Data Selector● Components and Scheduling● Looping Actions● Real world examples (with BA and Murdock)● A tank building montage(!)

What have we covered?

Page 32: Rules for Fools: The Rules Module

Background by Subtle Patternslicensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.