rules for fools: the rules module

Post on 05-Jul-2015

4.156 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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...

Starring

Will Hallas

b.a. baracus

Tweet me, fool:@willhallonline

and

Will's cat Elizaas

“howling mad”Murdock

Miaow.

● 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

I love it when a rule

comes together

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

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

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

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

DrupalCausality

Because this EVENT happened,

under these conditions, this

action will take place.

● 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

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

What are components?

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

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

What are looping actions?

REAL World Exampleswith BA and Murdock

Hey. I don't use Rules yet.

Can I use Rules to change the article node title to

include the node id?

● 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

Can I use Rules to email theadministrator when a new

comment is created?

● 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

How can I use Rules with Views Bulk Operations to

unpublish nodes?

● 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

● + Add rule

● Name rule - “Unpublish node”

● + Add condition (if required)

● + Add action

● Unpublish Content

● Data: node

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

● 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

Can Rules make me a sandwich?

Montage!

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

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

top related