Since version 7.x-2.2, you can have multiple workflows per content type, using multiple Workflow Fields per content type.
ATM however, adding a second Workflow Field to a bundle gives unpredictable results in some situations. This should be fixed.
In general, all functions should still work without specifying a workflow. The code will auto-detect a proper workflow. However, it must be possible to specify a workflow in certain cases.
Caveat:
- The good old Workflow Node submodule technically allows for multiple workflow per content type as well. However, The goal for this issue is to solve it only for Workflow Field. (But perhaps it will be solved for workflow_node, too.)
- Do not mix workflow_node and workflow_field in the same installation!
Some cases that should be reworked for multiple workflow_fields:
each occasion of workflow_node_current_state() where $field_name is not specified or NULL;each occasion of workflow_node_previous_state() where $field_name is not specified or NULL;- when deleting a state from a workflow (in the workflow Admin UI)
each occurrence of getWorkflowItem(), to be replaced by entity->workflow_transitions[]workflow_vbo: change workflow to new statefixed in #2168197-5: Add VBO support for workflow_field (using 'modify entity values')- workflow_vbo: change workflow to next state
- #2209359: workflow access & workflow field includes support for multiple workflows per entity, too
- #2240009: Multiple workflows per bundle/node_type & tokens
- #2217291: Workflow Tab as a Views display (allowing multiple Workflow fields per bundle, too)
- #2230833: Problems with ScheduledTransitions, with multiple workflowFields on a node (as per comment #11)
- #2243569: Multiple workflow per node & workflow_get_workflows_by_type()
- #2243941: Multiple workflows on a node & workflow_node
- #2446811: Permissiosn: Add support for multiple workflow fields in workflow_access
Comments
Comment #1
johnvIn #2207423-10: Workflow action triggers not firing , some facility is created in WorkflowTransiton->execute() to assist this goal:
Comment #2
johnvDue to other issues, a new function
_workflow_get_workflow_field_info()
now exists, and is called on above locations. So, the infrastructure is in place. Per location, the the result should still be evaluated.Comment #3
dimapu CreditAttribution: dimapu commentedJohnv, thank you for the update. I've studied the logic of the module since my recent question on Multiple workflow fields.
I considered the case when the node is created. When saving a node a
workflow_node_current_state()
is called, which finally calls a$workflow = workflow_get_workflows_by_type($entity->type, $entity_type)
.This last call returns just one $workflow even in case of multiple workflow fields. So I see two variants to deal with that:
workflow_get_workflows_by_type()
so that it returns array of workflows, Later, in theworkflow_node_current_state()
, we select the correct one according to the$field_name
.workflow_get_workflows_by_type_and_field($entity->type, $entity_type, $field_name)
, which will return the correct workflow. (I implemented this at home and it seems to work).Which will be better and more correct to use?
This is my first experience with drupal module, so I'd like to hear first an opinion of someone more experienced.
Comment #4
johnvWe must make sure to determine the $field_name as early as possible.
This only happens if workflow_node_current_state() is called without a $field_name. We should try to avoid this situation.
$field_name can have 3 values: '', which is in the case of workflow_node, when using workflow_field, or
NULLwhen the $field_name is not established yet. This 3rd case must be avoided.I always use
dpm(debug_backtrace());
to see where in the program I am.Comment #5
johnvHi, a first commit is here.
It fixes the problem when saving a new entity with 2 workflowfields.
Please continue testing and report back, so I can help you.
Comment #6
johnvThis second commit fixes workflow_access.
Comment #7
johnvComment #8
dimapu CreditAttribution: dimapu commentedHi, thanks for the commits. I've tested yet only after the first commit. It works fine when creating a node with few workflow fields and editing the workflow values on the edit node tab.
I looked also into Workflow tab.
workflow_tab_page()
receives from$workflow = workflow_get_workflows_by_type($entity_bundle, $entity_type);
just a single workflow. Therefore on this tab only state and transition for one workflow is shown.If we make
workflow_get_workflows_by_type()
return array of$workflow
, and make loop for each of them inworkflow_tab_page()
, it is enough to fix Workflow tab display. (However, not yet fixing the Workflow history table. Access rights to each of the workflow fields are also to be checked additionally, maybe with workflow access, haven't looked into it yet).workflow_get_workflows_by_type()
is used in few other locations, the most important beingworkflow_tab_access()
. It seems, this function does not really use the returned$workflow
to determine access rights. Instead, it goes through workflow fields later:Comment #9
dimapu CreditAttribution: dimapu commentedComment #10
johnv@dimapu, regarding #8: I've created a new issue #2217291: Workflow Tab as a Views display (allowing multiple Workflow fields per bundle, too) to address the Workflow Tab. We should ditch the code, and use a Views display.
This addresses also the problems in workflow_tab_access() and workflow_tab_page().
Comment #11
johnvHere is another problem:
when having 2 workflow_fields on a node, and both are scheduled independently, and 1 is executed, both are removed from the schedule.
This happens in WorkflowTransition.php:
And this happens in WorkflowScheduledTransition.php, deleting all scheduled transitions for both fields:
Comment #12
johnvComment #13
johnvComment #14
johnvComment #15
johnvComment #16
johnvComment #17
johnv#2168197-5: Add VBO support for workflow_field (using 'modify entity values') makes WorkflowField compatible with the VBO 'modify entity values' action.
So, using workflow Field, do not use 'change workflow state to new state'.
Comment #18
johnvComment #20
johnvAdded #2240009: Multiple workflows per bundle/node_type & tokens to the summary.
Comment #21
johnvComment #22
johnv@dimapu: regarding comment #3,I have created a new issue #2243569: Multiple workflow per node & workflow_get_workflows_by_type()
Comment #23
johnvComment #24
johnvI guess this issue can be closed, as most of the issues are addressed, and are available in current dev-version or upcoming 2.3 version.
Two small tasks remain. If any-one is interested, please open a new ticket for this.
Comment #27
johnv