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:

Comments

johnv’s picture

Title: Workflow Field does not support 2 workflow fields per Node type (Entity bundle). » Workflow Field does not support multiple workflow fields per Node type (Entity bundle).
Issue summary: View changes

In #2207423-10: Workflow action triggers not firing , some facility is created in WorkflowTransiton->execute() to assist this goal:

    // Store the transition, so it can be easily fetched later on.
    // Store in an array, to prepare for multiple workflow_fields per entity.
    // This is a.o. used in hook_entity_update to trigger 'transition post'.
    $entity->workflow_transitions[$field_name] = $this;
johnv’s picture

Due 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.

dimapu’s picture

Johnv, 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:

  1. modify workflow_get_workflows_by_type() so that it returns array of workflows, Later, in the workflow_node_current_state(), we select the correct one according to the $field_name.
  2. use smth like 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.

johnv’s picture

Issue summary: View changes

We must make sure to determine the $field_name as early as possible.

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 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 NULL when 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.

johnv’s picture

Title: Workflow Field does not support multiple workflow fields per Node type (Entity bundle). » Support multiple workflow_fields per Node type (Entity bundle).

Hi, 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.

johnv’s picture

This second commit fixes workflow_access.

johnv’s picture

Issue summary: View changes
dimapu’s picture

Issue summary: View changes

Hi, 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 in workflow_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 being workflow_tab_access(). It seems, this function does not really use the returned $workflow to determine access rights. Instead, it goes through workflow fields later:

<?php
foreach ($fields as $field) {
  $tab_roles += $field['settings']['history']['roles'];
  $history_tab_show |= $field['settings']['history']['history_tab_show'];
}
?>
dimapu’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes

@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().

johnv’s picture

Here 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:

    // Remove any scheduled state transitions.
    foreach (WorkflowScheduledTransition::load($entity_type, $entity_id, $field_name) as $scheduled_transition) {
      $scheduled_transition->delete();
    }

And this happens in WorkflowScheduledTransition.php, deleting all scheduled transitions for both fields:

  public function delete() {
    $result = $this->deleteById($this->entity_type, $this->entity_id);
    return $result;
  }
johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes
johnv’s picture

Title: Support multiple workflow_fields per Node type (Entity bundle). » [META] Support multiple workflow_fields per Node type (Entity bundle).
johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes

#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'.

johnv’s picture

Issue summary: View changes

  • Commit b3fa8dd on 7.x-2.x by johnv:
    Issue #2102409 by johnv: Removed ->getWorkfowItem() c.s., which is not...
johnv’s picture

johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes

@dimapu: regarding comment #3,I have created a new issue #2243569: Multiple workflow per node & workflow_get_workflows_by_type()

johnv’s picture

Issue summary: View changes
johnv’s picture

Version: 7.x-1.x-dev » 7.x-2.2
Status: Active » Fixed

I 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.

  • Commit a9b95cb on 7.x-2.x by johnv:
    Issue #2102409: Fixed some function (calls) dit not support multiple...

Status: Fixed » Closed (fixed)

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

johnv’s picture

Issue summary: View changes