1. Read more about workflow-ng: http://drupal.org/node/156282
2. Read more about the state machine API: http://drupal.org/node/202648
3. Use existing Drupal API functions where appropriate, found on http://api.drupal.org/api/5
4. Write a patch against the DRUPAL-5 branch of CVS for workflow-ng. Upload the patch to [**link to new d.o issue here**]

The admin interface should be added in its own include file states_admin.inc. Allow the creation of state machines for all supported entities (nodes, users). As nodes and users have different options (#roles, #types) it would probably be best to create a multistep creation form. First let the user choose the entity and then present the form on the second page. You can save the data in the database, as state machine definitions are cached by the states module. Create a new table for this, e.g. states_custom.

Provide options for all available properties except #attribute_name.
To create the state machines implement hook_states() -> states_states().
Of course, make it possible to edit and delete existing state machines. (but only the one defined through the admin interface).

Comments

fago’s picture

Title: GHOP: Create admin interface for the state machine API » GHOP #118: Create admin interface for the state machine API
deekayen’s picture

subscribing

corsix’s picture

Status: Active » Needs work
StatusFileSize
new17.88 KB

Implemented first draft of the admin interface. Does listing and creating of state machines, doesn't do editing and deleting yet.

tanc’s picture

Great work corsix. Looking forward to seeing what you come up with. Subscribing.

corsix’s picture

StatusFileSize
new1.23 KB

Experiencing some odd behaviour with multistep forms and default values for #type=checkboxes.
Attached is a minimal example of this; #default_value has no effect when the form is multistep, but works fine when only a single step.

Would appreciate it if you could look over the example and see if I'm using the forms API incorrectly, or if it is misbehaving.

fago’s picture

corsix, yes this a known bug of multistep forms in d5. it's odd.

I've been using this workaround in workflow-ng:

    //a formAPI bug lets default_value not work, so we have to care about this ourself
    if ($checked) {
      $form['checkbox']['#attributes']['checked'] = 'checked';
    }

I've just done a quick review, the code already looks good, I'll give it a deeper review in a few hours.

Just an idea:
Perhaps you can save some hidden values, if you use one value, which holds an array holding all values and serialize it. But implement it as you like.

fago’s picture

* don't forget to add an upgrade procedure for creating your table
* don't call the admin menu point "State Machine API" - an API is for modules, not for users. Hm let's call it "Configurable State Machines" OR "Custom State Machines" - as you prefer.
* Please don't use "Node" in the UI, use "Content" instead like workflow-ng
* capitalizing - only capitalize the first letter of a sentence, so "Initial State" -> "Initial state"
* for states there is a difference between state == '' and state == NULL. That matters in particular for the init state, so better just set the init state to NULL or don't set it, if the init state is given as ''

apart from that, the patch looks already fine. In particular I like the 'review' step!

corsix’s picture

Status: Needs work » Needs review
StatusFileSize
new26.06 KB

Second draft, implements machine editing and deleting, addresses the issues you raised, and allows you to go backwards as well as forwards through the wizard.

tanc’s picture

Hi corsix, this is working quite well so far. But for some reason it looks like the 'Set a machine state' action is not working. I've configured a Custom state machine and called it 'Publishing workflow'. I've set a cclink to trigger these three actions:

1. Display the current Workflow state using the token [node:state-custom_state_1]. Result is correct state is displayed.
2. Set a machine state. I've used one of my three states defined in my 'Publishing workflow' as the value.
3. Display the current Workflow state again, using the same token as before. Result is same state is displayed, not the updated one.

It seems from this that the Workflow state isn't being updated. Maybe I'm doing something wrong though? Hope this helps.

tanc’s picture

Also, when creating a custom content machine state, some errors are thrown when defining specific Content types to be used. The specified Content types aren't saved and defaults back to (all). The error is:

warning: unserialize() expects parameter 1 to be string, array given in /Library/WebServer/Documents/newqafac/sites/all/modules/workflow_ng/states/states_admin.inc on line 528.
warning: array_keys() [function.array-keys]: The first argument should be an array in /Library/WebServer/Documents/newqafac/sites/all/modules/workflow_ng/states/states_admin.inc on line 528.

I'm not sure if posting this kind of thing helps the developers or is just annoying. My intention is to help, let me know if its annoying...

corsix’s picture

StatusFileSize
new26.89 KB

Thanks for catching that one; due to some restructuring, the content types no longer need to be unserialized.

fago’s picture

Status: Needs review » Needs work

great!

* when updating a site I got this errors:
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/fago/web/drupal-5/update.php on line 309.
* warning: Invalid argument supplied for foreach() in /var/www/fago/web/drupal-5/update.php on line 542.

return array() in your update.

* codestyle at line 576 admin.inc: -> else {

* I would say it's more intuitive, to let the update case handle to create case too, instead of letting the create case handling the update case too. Soo I would suggest to let the "create submit handler" use the "update submit handler".

* You can set #validate to define another validation handler

* Please don't use arg(3) in a submit handler, instead put the value you need in a form value. E.g. you could put the sid_to_update in form element type value and so you could even use one submit handler for both forms - just detect the sid_to_update form_value. Again you can specify a form submit handler with #submit.

*when editing a state machine restricted to content types, the previously selected content types won't appear again.
*when editing the final button is also labelled "Create". This might be confusing for people

*first enable any states, go ahead, go back and deselect any states, go ahead and you get an error until there are states defined:
warning: implode() [function.implode]: Bad arguments. in /var/www/fago/web/drupal-5/sites/all/modules/workflow_ng_5/states/states_admin.inc on line 340.

*defining a user state machine works, but when I edit it I get errors:
warning: array_combine() [function.array-combine]: Both parameters should have at least 1 element in /var/www/fago/web/drupal-5/sites/all/modules/workflow_ng_5/states/states_admin.inc on line 617.

*In the custom state machine overview other available state machines, defined by other modules, are also listed. I think we should only list the custom defined state machines there. You could specify #module == 'States' to identify them.

regarding:
function states_admin_checkboxes_multistep_fix($checkboxes) {
foreach ($checkboxes as &$checkbox) {

the usual way to iterate over form elements is
foreach (element_children($elements) as $key) {
// work with $elements[$key];
}

@Tanc: Your help is welcome. Indeed, I had introduced a bug in the the workflow-ng development snapshot which prevent the action from working. I've fixed that now, so update workflow-ng.

corsix’s picture

Status: Needs work » Needs review
StatusFileSize
new28.09 KB

Addressed the above points.

fago’s picture

Status: Needs review » Fixed

you still had one arg(3) in the delete submit handler, but no big deal. I've just fixed that myself.

The patch works fine. Great that you have even removed the "unset" parameter. -> Committed to 5.x :)
-> Again, good work corsix! thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.