Problem
The workflow_field_choices function is expected to return "the states the current user can move to for a given node". However, it only returns the states that the first node of the specific type that was loaded this cycle could move to.
A glimpse at the code:
function workflow_field_choices($node, $force = FALSE) {
global $user;
static $choices = array();
if (!isset($choices[$node->type])) {
$choices[$node->type] = FALSE;
...
}
return $choices[$node->type]
}
Since $choices is set to be static and is stored by type, if you load up a second node, or need to check the node for a different user, or need to check the node with a different setting for 'force', it will fail.
(If you are wondering is there is a use case this causes problems in, there is. I encountered this because I am cloning a node, and that requires loading up a first node (which sets the $choices[) and then saving a new one, which causes workflow_node_insert to trigger, which fired workflow_transition, which calls this and gets the wrong types, leading to either no transition to the first state, or the wrong one.)
Proposed resolution
I'm not familiar enough with the workflow code to know exactly why this is being done (I assume it is to speed up load time), but this seems like a method that should not be storing things statically. If we still need to, I see a few options:
- We might be able to store by $nid (but this could still cause problems if a node undergoes multiple transitions at once, or if the choices programmatically get changed)
- We could just not store anything and accept the slight slowdown in load time. ie:
function workflow_field_choices($node, $force = FALSE) { global $user; $choices = array(); ... } - We could add an argument for ignoring the static variable. ie:
function workflow_field_choices($node, $force = FALSE, $ignore_cache=FALSE) { global $user; static $choices = array(); if (!isset($choices[$node->type] || $ignore_cache)) { ... } }
Hope this is a useful bug report (it's my first). I'll glad provide more info if needed.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 1967794.patch | 2.77 KB | nancydru |
Comments
Comment #1
nancydruPlease check this out.
Comment #2
nancydruCommitted