Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am attempting to create a block of nodes with a specific workflow state. When adding a workflow state filter in views, the workflow state always shows as unknown even if one or more states have been selected. A screenshot of the filter section of my view is attached which shows the (in Unknown) in the filter. Unfortunately, the view will not save in this state. Interestingly enough the query seems to be picking up the selection:
SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created
FROM
{node} node
LEFT JOIN {workflow_node} workflow_node ON node.nid = workflow_node.nid
WHERE (( (node.status = '1') AND (node.type IN ('referral')) AND (workflow_node.sid = '6') ))
ORDER BY node_created DESC
LIMIT 5 OFFSET 0
Comment | File | Size | Author |
---|---|---|---|
#6 | fix_workflow_views_handler_filter.patch | 767 bytes | dozymoe |
snapshot2.png | 11.75 KB | joel_osc |
Comments
Comment #0.0
joel_osc CreditAttribution: joel_osc commentedfixed grammar...ugh.
Comment #1
Bastlynn CreditAttribution: Bastlynn commentedUnfortunately I wasn't able to replicate this one. I did put in some fixes in the dev branch for filtering the available states by active/inactive state that may have been contributing to how your setup got to this point.
You may need to clear cache to get Views to pickup the Workflow related features.
Otherwise I'm going to close it - but if you can show me how to replicate this, then I'll be glad to take a second look.
Comment #2
joel_osc CreditAttribution: joel_osc commentedI have figured out that you need to have two workflows created to reproduce this problem. So the easiest steps would be:
1. Add a workflow called 'workflow-1'
- add state test1
2. Add a workflow called 'workflow-2'
- add state test2
3. Enable workflow-1 on Basic Page
4. Create a view of content type Basic Page
- add filter workflow current state = test1
...and that should do it. If you delete 'workflow-2' the problem goes away. Another funny thing is that if you go to add back 'workflow-2' you get an error that it already exists.
Let me know if this helps. Cheers and thanks for the awesome module.
Comment #3
dylanhuang CreditAttribution: dylanhuang commentedworkflow-7.x-1.x-dev:
The issue cause by "workflow_views_handler_filter_sid.inc" this file:
if (count($workflows) > 1) {
$states = array('' => t('No state'));
foreach ($workflows as $wid => $name) {
foreach (workflow_get_workflow_states_by_wid($wid, $options) as $state) {
$states[$name][$state->sid] = check_plain($state->state);
}
}
}
else {
foreach (workflow_get_workflow_states($options) as $state) {
$states[$state->sid] = check_plain($state->state);
}
}
Only change $states[$name][$state->sid] = check_plain($state->state) to
$states[$name][$state->sid] = check_plain($name . ': ' .$state->state) this issue can be fixed.
Because in the "views-7.x-3.0" module, file "views_handler_filter_in_operator.inc" function "admin_summary" line 300 to line 309
foreach ($this->value as $value) {
if (!isset($this->value_options[$value])) {
unset($this->value[$value]);
}
}
// Choose different kind of ouput for 0, a single and multiple values.
if (count($this->value) == 0) {
$values = t('Unknown');
}
The workflow get_value_options() function's return is not a pure array, so the below statement will unset the states which have been selected.
if (!isset($this->value_options[$value])) {
unset($this->value[$value]);
}
Comment #4
dylanhuang CreditAttribution: dylanhuang commentedSorry,
Only change $states[$name][$state->sid] = check_plain($state->state) to
$states[$state->sid] = check_plain($name . ': ' .$state->state) this issue can be fixed.
Comment #5
joel_osc CreditAttribution: joel_osc commentedThe fix in #4 works perfectly. Thank-you.
Comment #6
dozymoe CreditAttribution: dozymoe commentedAnother +1 for the fix at #4.
And the patch with no other changes made, except the fix in #4.
Changing the status to need review??
Comment #7
Bastlynn CreditAttribution: Bastlynn commentedLooks good to me. If someone comes up with a follow up patch to preserve the pretty select drop down I'll gladly take it, but I'd rather an ugly display than having a mystery "Unknown" in the configuration display.
Patch applied to the 7.x branch.
Comment #7.0
Bastlynn CreditAttribution: Bastlynn commentedremoved strong from code section