Views Bulk Operations & Exposing Rulesets as their Actions
No theory, no slides, let’s get down to business & build something bad ass through the User interface!
I am going to encourage participants to follow along in your drupal installs, please have something close to the default configuration ready to go when you get there so we can start right away & you can keep up as I go.
I would like to have more experienced people sit near less experienced folks, to help them keep up.
My goal is to familiarize everyone with these sweet modules as we build a writers queue & simple submission/moderation system with them together. No one left behind:)
A basic function of Views Bulk Operations allows you to change selected fields on a bunch of nodes at once. You can filter nodes like you would with exposed filters on any view, then select all the ones you want to update, input the value to change the fields to on selected nodes, press your submit button & wala! All nodes updated with your new value. But that’s just the tip of the iceburg of what can be done with VBO.
I’ll show you how to submit a VBO to a custom ruleset, which will allow the specific node changes we want to be initiated by users with, otherwise, very limited access.
I used this technique to set up a “writers queue” for a company a few months back. When combined proper configuration of role permissions, this allows you to make it so: authors can only edit the pages they have checked out (and not checked back in yet), set time stamps, limit the amount of pages checked out at once, & set up an easy moderation system for rejecting or publishing content submitted by authors. I had this set up another way initially (regular views & “update from URL” links), but this way is much more robust and most importantly: not susceptible to user manipulation in any way.
This is really cool stuff that can all be done using modules and configuring them directly through the Drupal UI – most would write a bunch of code for this type of thing, I say don’t bother:)
This is how the session will go:
Create new role “Writer” & user Bill with writer role.
Configure Masquerade to be able to switch to Bill (by adding him to “Masquerade Block Quick Switch users”)
& add the masquerade block to the left nav.
Set permissions for writer role to be able to access content & edit own page and story nodes.
Add a new fields on the “page” & story content types:
Checked Out Int = checkedout_int = Intager = single on/off checkbox. Allowed values:
Create a test story and page node.
Set bill to the author of one of them. See how he can edit only that one and not the other.
Create new “writers queue” view.
Set style to bulk operations.
Set Access to role & allow writer (this is so the writer role can access this view without the access all views permission).
Add page display set URL to “writers-queue”.
Check out how you can change the node values using the “Modify Node Field” operation.
Create new rule set with one argument of content.
What you call this ruleset will be the name of the submit button on you’re VBO.
Add a condition for making sure it’s not already checked out.
(field has value on checked out int field)
Add an action for checking it out.
First modify node field to check the check out box.
Then custom PHP to set the UID of the node to the currently logged in user:
$node->uid = $user->uid ;
return array("node" => $node);
Add a Configurable message to let them know it worked.
Clone that rule & make one that validates the opposite way with only an error message (delete processing operations).
Change the weight so the error comes first, or both messages will show up.
Change the Views operation from “modify node fields” to the custom ruleset.
Filter the view so only pages that are not “checked out” show up.
Bewm! Now writers can log in and check-out content from the writers queue – and edit it, because it makes them the author of the node.
But they are not able to edit any of the fields that are changed behind the scenes by the VBO executing the ruleset.
Now we can go on with the second half (that really makes this thing complete & useful):
Clone view, call it “writers_check_back_in”, change page displays URL to “writers-checked-out”
Add Argument “Node: User posted or commented”, provide default argument: “User ID from logged in user” & save new view.
Add new ruleset: “Check Back In” with argument of content.
Add new CCK int field “submit_for_review” to story and page content types, allowed values:
1|Submit for Review
Add new rule “Check page in” to “Check Back In” content type.
Add new action: Populate a field: content: submit_for_review: checked.
Add new action: Populate a field: content: checked_out_int: un-checked.
Add new action: Show configurable message on the site: “Page submitted for moderation!”
Change VBO setting in “writers-checked-out” view to submit to “Check back in” ruleset.
Filter “checked out” view to only show nodes that are “check out” but not “submitted”
Content: Checked == 1
Content: Submit for != 1
Filter “writers queue” view:
Content: Checked != 1
Content: Submit for != 1
Add “writer” text field to both content types.
Add two new actions to “Change check” rule in “check out page” ruleset:
Load content author.
Populate Content’s field ‘field_writer’ > Specify the fields value with PHP code:
0 => array(‘value’ => $author->name),
Use weight to make sure those two rules go after the UID is set with the custom php & before the confirmation message.
Add new action to “Check page in” rule in “Check Back In” ruleset:
$node->uid = 0;
return array(“node” => $node);
Add a menu with links to both views: Get Pages & My Pages
Add menus block to left nav, only for writers roll.
Clone “writers queue” view to “moderators queue”.
Change filter to only show nodes that are submitted = 1
Add writer field to display.
Change page displays URL to moderators-queue
Change access to administator role, instead of writer.
Add new CCK int field “rejected” to story and page content types, allowed values:
Add new ruleset “reject”.
Add new rule “Reject Page” in that ruleset.
3) Limit the number of pages the writers can check out at a time.
4) Set up a “queue manager” VBO/Ruleset for a moderator to use for rejecting (with fix-it notes) or publishing content submitted by writers.