2

In the admin section, for any given node, I need to add a dropdown field that lets QA assign that node to a developer who had previously made changes to the node's workflow state. I am currently using the workflow module (https://www.drupal.org/project/workflow). This field needs to be populated with users who have changed the node's workflow state before. So, I'm working on a module that can do this. My question is, how do you programmatically get the workflow state transition history for a given element?

For every revision of a given node that has involved a workflow change, I would need the following information:

  1. The state or state id (sid) that it was changed to.
  2. The uid of the user that made the change.
  3. The order in which the workflow state transitions were made.

I tried node_revision_list, but it does not include revisions that only change the workflow state. (Because it's not looking at the workflow_node_history table).

I can get the information I need directly from the database by running the following query, but I don't want to do any database-hacking if this functionality is already in Drupal somewhere.

SELECT sid, uid  FROM `workflow_node_history` WHERE `nid` = ? ORDER BY stamp asc

Is there a Drupal function that already does this?

  • 1
    Are you using any contributed modules to implement this workflow? If so can you edit your question to indicate which ones (including the project URL). That would avoid making assumptions about which modules you're using. Such as the one about the Workflow module in the answer below .. – Pierre.Vriens Jun 26 '15 at 13:43
1

The Workflow module has a lot of API calls that you can use to get the relevant information you need.

Here are all the workflow functions you can access

It seems like you might be looking specifically for the workflow_get_workflow_node_history_by_nid function

Here you supply a node ID and it will return the history results as an object where you can find the information you need. It even joins it with the users table so you have all the relevant user information.

  • I ended up using workflow_transition_load_multiple, which seems to have replaced workflow_get_workflow_node_history_by_nid. – TMorgan Jun 26 '15 at 16:00
  • Great, glad I could help you find the right path. Cheers. – VanD Jun 26 '15 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.