« Workflow 1.0 | Main | Workflow Plugin Contest »

April 13, 2005

Extending Workflow

My favorite part of developing Workflow was implementing a plugin system for it. Now it is time for me to tell you folks about all of the ways you can extend and customize Workflow for your specific situations.

Workflow Callbacks

All Workflow callbacks can be added to through the add_callback method of the MT module:

MT->add_callback ('Workflow::CALLBACK_NAME', $priority, $plugin, \&subroutine_ref);

Creating a Workflow plugin

To add your own custom code to Workflow, simply create place your code in a .pl file in the /plugins/Workflow/plugins/ directory. What code are you going to put in that file? I will cover that next.

Adding a permissions setup option

The list of permissions setup options you can select from when first setting up a blog for Workflow can be modified. The two default options are defined in /plugins/Workflow/workflow.pl. To add your own, use the add_setup_option method of the Workflow module. That method takes two arguments: the option name and a hash reference containing all of the details for that option.

require Workflow;
Workflow->add_setup_option ('Option Name', {
    desc => 'Option description',
    can_grant => sub { 1; },
    can_publish => sub { 1; }
});

The values for the can_grant and can_publish keys are subroutine references that are passed parameters in the fashion of normal Movable Type callbacks with the following parameters: the Workflow::App object and the MT::Permission object for the current blog and author being setup. The subroutine should return a true value if the author should be allowed to grant publish permissions or publish respectively.

For example, the Open Publishing setup option uses the following subroutines to give all those authors who can edit all posts permission to grant publish permissions and all those authors who can post publish permission.

can_grant => sub { $_[2]->can_edit_all_posts },
can_publish => sub { $_[2]->can_post }

And beyond that, every setup option can be extended beyond its initial setup. Simply add a callback to either Workflow::OPTION_NAME::SetupGrant or Workflow::OPTION_NAME::SetupPublish where OPTION_NAME is the name of the setup option (e.g. "Open Publishing"). And there are global callbacks that are called no matter what setup option was selected: Workflow::SetupGrant and Workflow::SetupPublish.

Supplementing the entry transfer process

To whom can an entry be transferred?

A Workflow plugin can restrict the list of authors to whom an entry can be transferred. The Workflow::CanTransfer callback, if the subroutine returns a false value, can prevent an author from appearing on the list of available authors to whom an entry can be transferred. The callback subroutines are passed the following parameters: the Workflow::App object, the MT::Entry object representing the entry that will be transferred, the MT::Author object representing the author to whom the entry would be transferred, and the MT::Author object representing the author who is doing the transferring (not necessarily the author of the entry).

A Workflow plugin could define a list of authors that are responsible for particular categories and then only allow those authors to be transferred entries for those categories.

What to do before an entry is transferred?

The Workflow::PreTransfer callback takes the same parameters as the Workflow::CanTransfer callback and is only run right before an entry is transferred after it is verified that it can be transferred to the specified author.

What to do after an entry is transferred?

The Workflow::PostTransfer callback is run after the entry is transferred. It takes the following parameters: the Workflow::App object, the MT::Entry object representing the entry transferred, the MT::Author object representing the author from whom the entry was transferred, and the MT::Author object representing the author who did the transferring. For example, this is the callback that the plugin uses to send the entry transfer notification.

A Workflow plugin could implement an entirely new form of notification, for example sending an instant message with the Net::AIM module.

Supplementing publishing permissions

The Workflow::CanPublish callback is called when an author attempts to publish an entry. If the callback returns a false value, the entry will be switched to draft. It takes the following parameters: the current MT app (either Workflow::App or MT::App::CMS), the MT::Author object representing the author attempting to publish, and the MT::Entry object representing the entry attempting to be published.

Posted by rayners at April 13, 2005 08:27 PM

Trackback Pings

TrackBack URL for this entry:
http://mt.rayners.org/mt-tb.cgi/502

Comments

Post a comment




Remember Me?

(you may use HTML tags for style)