Rules:
Duct Tape for Drupal

Ryan Price
Blink Reaction
@liberatr

slides.com/ryanprice

9 years in Drupal, 15 in web

 

Orlando, FL

 

FLDrupalCamp.org

April 11-12, 2015

 

Faves: Theatre, Pottery, Photography, Podcasts, Beer, Coworking, Mentoring, and Open Source

DrupalEasy
Podcast

DrupalEasy.com/podcast

 

@DrupalEasy

 

Facebook

 

iTunes, Stitcher, Miro or
your favorite podcast app.

BATTideas.com

art & technology




OurYellowHouse.com

community & work

Lashing

Lashing

[lash-ing] verb

1. to secure items together in a somewhat rigid manner

Lashing

  • non-permanent
  • utilitarian
  • improvised
  • re-usable materials
  • methodical

What about Duct Tape?

What about Duct Tape?

"Lashing for Drupal"
did not have the same ring to it. :P

Duct Tape

  • non-permanent
  • utilitarian
  • improvised
  • re-usable materials
  • methodical

Duct Tape!

Rules

Custom Code

Rules

Drupal is not about writing code

Drupal is all about features

(not those features)

"using the internet to eliminate middlemen"

Dries Buytaert

the programmer is a middleman between your data and your business

not knowing how to code can be as bad as having as having a middle man

How to: Rules

1. Deconstruct
2. Modify
3. Construct
4. Compose
5. Trigger

Title Text

when this happens

if this is true

perform this action

Event:

Condition:

Action:

before I leave for work

if there are dark clouds in the sky

bring the umbrella from the hall

Event:

Condition:

Action:

after I leave for work

if the day is not Friday

get credit card from wallet

purchase coffee with credit card

if the time is before 8:45am

when this happens

if both of these are true

set up this data

perform this action with data

Modify
(demo)

Woah, not sure what this rule does...

I can edit this "Test" message though.

Construct
(demo)

If I unpublish a node,
delete all the comments

What Event?

Saving a node

What Condition?

If it's unpublished

What Action?

Delete the comments

Until we learn to use "Loop", we have to delete comments one-by-one

/admin/config/workflow/rules/reaction/add

When this happens...

I have an event

Add a Condition for Unpublished

What about
"unpublished"?

I want the opposite of published

Event and Condition

I Need an Action to Perform

There is no Action

referring to Comments

Comments are

Entities, though

What is all of this?

TODO

What is all of this?

I can drill down into a Node and one comment at a time

Event, Condition and Action

...but only deletes the first comment

I'll add a Loop

Drill down to comment list

Change "Current List Item" to

something more meaningful to this rule

Delete Entity needs to be nested under Loop

Don't forget to Save!

Still one more edit needed

Drill down to comment list

Change "Current List Item" to

something more meaningful to this rule

The Finished Rule

Loop over and Delete the right way

Compose

1

2

3

4

5

Loop

Send email to these users

Loop

Run another Rule on these Nodes

Rule Inception

Notice, there is no "Event" in a component

Rules Components

Compose
(demo)

Trigger

Triggering Components

Views Bulk Operations

Triggering Components

Drupal Commerce

Triggering Components

Entityform

Trigger
(demo)

Drupal 8?

Site building based on Drupal 8 core integration wins

  • Admin UI usability improvements

  • Simple Views Bulk operations in core

Reusable components

  • Plug-in based architecture & fully object-oriented code

  • Rules data selector for tokens, contexts and other use cases

  • Typed data widgets & formatters

  • Embeddable Rules UI components to integrate actions & conditions

Evolved developer experience

  • Unified DX based on Drupal 8 plug-in system

  • Symfony 2 event system integration

  • Deployable config via CMI

Milestones

  1. Drupal 8 core integration & Rules core engine          $$$

  2. Rules core API completion

  3. Rules 8.x release

Rules Recipes

at DropBucket.org, the Drupal Pastebin

Useful Rules Modules

Rules Scheduler

https://www.drupal.org/project/rules

Create Components

The "Event" is Cron

ex. Reminder: You haven't edited your profile in a year

Views Bulk Operations

https://www.drupal.org/project/views_bulk_operations

Create Components

Edit View "Bulk Operations" Field and add your Component

Make sure you have a "Node" Parameter
(or whatever Entity your view pulls)

Maillog

https://www.drupal.org/project/maillog

Show me the emails

Log all messages

Reroute instead of sending

Commerce

https://www.drupal.org/project/commerce

Enabling Payment Types

Adding Taxes

Price Adjustments

Rules Forms Support

https://www.drupal.org/project/rules_forms

Event: When a form is being validated

Invalidate a form before it gets saved

Validate fields, display custom messages

Don't need to use Form API

Used by Resource Conflict

Resource Conflict

https://www.drupal.org/project/resource_conflict

Check if an event is in the same room at the same time

Use Taxonomy Terms for "rooms"

Can invalidate the form, so it won't be saved if a conflict exists

Workflow Rules

https://www.drupal.org/project/workflow

React to changes in Workflow State

e.g. Draft, In Progress, Needs Review, etc.

Cache Actions

https://www.drupal.org/project/cache_actions

    Clear Drupal cache bins
    Clear CSS/JS cache
    Clear the cache of specific views
    Clear the cache of specific panel pages
    Clear the cache of specific mini panels

 

 

 

Entityforms

https://www.drupal.org/project/entityform

Excellent Rules support built in

Rules drive email Notifications

Logintoboggan Rules

https://www.drupal.org/project/logintoboggan

Event when the user account is validated.

Organic Groups

https://www.drupal.org/project/og

Events when a user is added to a group,

Joins/Leaves a group

When group content is added

Rules Repeated Events

https://www.drupal.org/project/rules_repeated_events

My preferred means of creating recurring events.

Good example of Provided vs Parameter

Context Rules

https://www.drupal.org/project/context_rules

Event when a Context is activated,

from the Context module

Rules:
Lashing for Drupal

Ryan Price
Blink Reaction
@liberatr

slides.com/ryanprice

Made with Slides.com