Create workflow programmatically

Events happening in the community are now at Drupal community events on www.drupal.org.
sagarmitra's picture

Can anyone please give me an example of how to create a workflow programmatically? I have a workflow already created. I need to invoke state change on a submit event.

Comments

Have you taken a look at

geekgirlweb's picture

Have you taken a look at Maestro for D7? And Workflow for D6?

Re: Maestro

benanderson's picture

gamerxgirl: I haven't had a chance to test Maestro out yet, have you? Do you think it's ready for production?

I do this manually

kmoll's picture

There are modules out there that will do most of it for you, but if you wanted a manual way you can create a field called workflow, give it allowed values of 'Daft' 'Submit' 'Publish' or whatever works for you application. Now every time someone submits a post it will change the field to whatever the value of work flow is, and you can use views to grab articles in a different state. You can further customize or give more functionality to the process by using hook_nodeapi, and testing for the value of the workflow field and run any script you want based upon certain conditions.

The modules usually work well, but I found for my application it needed too much customization, so I build my own workflow and it was surprisingly easy. Now I have complete control over it and can tweak or enhance it very easily.

Example for workflow

sagarmitra's picture

Can u give me a code example of how this is achieved. I have used the logic of changing the values of "sid" which represents the next workflow state. Is there a better way to do this? An illustrative example would be helpful.

Well, most of it isn't code,

kmoll's picture

Well, most of it isn't code, unless you really want to customize what happens when something is set to a certain state. But what I do is create a cck field called "Workflow", which you can do in the edit screen for a content type. Set the field to be a select, and give it allowed values. Set permissions for the roles you need access to that to be able to view and edit that field. Then when someone submits a node, they select the state that the node should be in. For me it would either be Draft, Submit, Reviewed, Published. Which ever one is selected will be the value of the workflow field when the node is saved.

Then you can set views to filter nodes based on the value of that field. For instance, I give users a view of their draft articles, so I filter the articles based on the workflow field, and their uid.

I also have a trigger set so when the article goes from view to publish, it actually publishes the article.

All that is done without custom code, just configuring the cck field, using views to filter, and using triggers based on the value of the workflow.

if you need to do something else custom you can create a module and use hook_nodeapi.

<?php

/**
* Implements hook_nodeapi
*/
function yourmodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){

}

for the $op you can use a switch statement to get either 'insert' or 'update', and put whatever script you want in there. If you google the hook_nodeapi, you will get all the info you need concerning that hook.

Happy to help out if you have any other questions.

kmoll092

Boston

Group categories

More Specifically

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: