Updated: Comment #1
Problem/Motivation
Working with actual workflow state values in site glue code is somewhat troublesome. Using integers for identification of states makes little sense in this case, so one end up with a custom reverse map to retrieve a sane name of the current workflow state:
function example_workflow_state_map($sid) {
$map = array(
1 => 'creation',
2 => 'draft',
3 => 'submitted',
4 => 'approved',
5 => 'rejected',
);
return $map[$sid];
}
The configured human readable name for states isn't a reliable solution for glue code.
Proposed resolution
One of the following:
- Convert {workflows}.wid and {workflow_state}.sid to varchar. {workflow_state}'s primary key will then consist of both wid and sid.
- Add additional machine readable columns to these tables.
- Make the possible states of a workflow resemble the options of a core 'List' field, (which have code and name).
Working with workflowfield.module it should be possible to use the field's value directly as state:
function example_node_update($node) {
if ($node->field_workflow_state[LANGUAGE_NONE][0]['value'] === 'draft') {
…
}
}
Remaining tasks
- Discussion, decision, implementation. 7.x-2.x? 7.x-3.x? 8.x-1.x? 8.x-2.x? OMG 9.x-1.x?
- Make the Workflow State a true, named, exportable entity, and change the current Admin UI to a more Entity-like screen.
User interface changes
None.
API changes
…
Comments
Comment #1
kaareComment #2
johnvI've added some details above.
Regarding the solution: recently most objects (workflow, 3xtransitions) are true entities. Workflow State is not yet. Converting it to an entity, including a machine name and entity 'Admin UI' should be easy for someone familiar with Entity (Admin UI) API.
Regarding the update path: If we choose to keep the current {workflow_state}.sid and add a name to the State itself, we adhere to Entity standards (table key = ID, exportable = name), and there should be no problem to do this in 7.x-2.x.
Regarding future developments: if we stay close to e.g. core List fields, we may select the possible states from any property or field, like OG makes any entity a group.
See #2192319: Add Workflow to any field, property
Comment #3
kaareI like #2192319: Add Workflow to any field, property which would render this issue a duplicate. However, is that realistic for 7.x-2.x? As an interim step it seems like option 2 (table key = ID, exportable = name) is the better one :-)
Comment #4
johnvThe current dev-version contains WorkflowStates as real entities. A machine_name is already added for WorkflowConfigTransitions.
This makes it easy for some-one to create a patch for this.
Comment #5
johnvThis is committed here.
Thanks to preddy for providing the patch.
Comment #8
johnv