Display the workflow in the node when viewing the node?

stodge - May 8, 2009 - 12:43
Project:Workflow
Version:6.x-1.1
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Can I display the workflow details (viewable in the Workflow tab) with the node when viewing the node? I'd prefer to see the workflow in the node so that the user has all the info in one place and they don't have to click the tab to change state.

Thanks

#1

stodge - May 14, 2009 - 12:44

I could try to create a patch if someone could give a hint as to what changes are needed.

#2

dawansv - June 10, 2009 - 22:20

Here is a solution that does not require changing the workflow module.

You can call the function that creates the workflow tab content from either your node template or a block. The trick is to include worlflow.pages.inc first.

So here is some code I have in my node.tpl.php (well in my case it's actually for a content type called resource, so its really in node-resource.tpl.php to be exact).

<?php
     
include 'sites/all/modules/workflow/workflow.pages.inc';
      print
'<hr />';
      print
strstr(workflow_tab_page($node),'<table');
?>

For the last line I used a bit of a hack to trim everything except the history table which is the only thing I want there--it's the only table and the last thing in the html output (as of now at least, so I have to keep an eye when updating the module). But you can display the workflow form as well by just doing print workflow_tab_page($node). Note that this does not remove the Workflow tab of course, which in my case I still want.

If doing this is in a block, you would have to do a node_load first...

<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2)=='') {
 
$node = node_load(arg(1));
  include
'sites/all/modules/workflow/workflow.pages.inc';
  print
'<hr />';
  print
strstr(workflow_tab_page($node),'<table');
}
?>

As for the include, make sure it is the right path, but this should be if you follow drupal standard recommendation.

#3

dman - June 10, 2009 - 23:11

Do you not already see it in the normal node form?
I do

... perhaps it's just permissions, or perhaps you didn't see it because it's collapsed.

I can't imagine that strstr(workflow_tab_page($node),'<table'); is a very safe way of changing your form!

#4

dawansv - June 27, 2009 - 18:06

Your snapshot above is in edit mode right? Indeed I see the workflow info in edit mode. The issue here is to display the workflow info when viewing the node (view tab) not editing it, in my case the workflow history which is essential for "super users" to see right away (not just under the workflow tab)

And yes I would agree the strstr business is definitely ugly. In my case because this is only displayed for a handful of super-users so I am not too worried because even if it breaks regular users do not see that.

#5

rickauer - August 15, 2009 - 19:14

Hi,

I also think there should be an option to display the "workflow history table" in non-edit mode. The hack above works and inspired me for another bad hack ;) But I believe it's a little nicer, since it's not messing around with strstr() - basically, it's just duplicating workflow_tab_page(). But I would really appreciate a solution of some professional niveau... Thanks!

<?php
 
include 'sites/all/modules/workflow/workflow.pages.inc';
 
$wid = workflow_get_workflow_for_type($node->type);
 
$states_per_page = variable_get('workflow_states_per_page', 20);
 
$result = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 1 ORDER BY sid");
  while (
$data = db_fetch_object($result)) {
   
$states[$data->sid] = $data->state;
  }
 
$deleted_states = array();
 
$result = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 0 ORDER BY sid");
  while (
$data = db_fetch_object($result)) {
   
$deleted_states[$data->sid] = $data->state;
  }
 
$current = workflow_node_current_state($node);

 
// theme_workflow_current_state() must run state through check_plain().
 
$output = '<p>'. t('Current state: !state', array('!state' => theme('workflow_current_state', $states[$current]))) . "</p>\n";
 
$output .= drupal_get_form('workflow_tab_form', $node, $wid, $states, $current);

 
$result = pager_query("SELECT h.*, u.name FROM {workflow_node_history} h LEFT JOIN {users} u ON h.uid = u.uid WHERE nid = %d ORDER BY hid DESC", $states_per_page, 0, NULL, $node->nid);
 
$rows = array();
  while (
$history = db_fetch_object($result)) {
    if (
$history->sid == $current && !isset($deleted_states[$history->sid]) && !isset($current_themed)) {
     
// Theme the current state differently so it stands out.
     
$state_name = theme('workflow_current_state', $states[$history->sid]);
     
// Make a note that we have themed the current state; other times in the history
      // of this node where the node was in this state do not need to be specially themed.
     
$current_themed = TRUE;
    }
    elseif (isset(
$deleted_states[$history->sid])) {
     
// The state has been deleted, but we include it in the history.
     
$state_name = theme('workflow_deleted_state', $deleted_states[$history->sid]);
     
$footer_needed = TRUE;
    }
    else {
     
// Regular state.
     
$state_name = check_plain($states[$history->sid]);
    }

    if (isset(
$deleted_states[$history->old_sid])) {
     
$old_state_name = theme('workflow_deleted_state', $deleted_states[$history->old_sid]);
     
$footer_needed = TRUE;
    }
    else {
     
$old_state_name = check_plain($states[$history->old_sid]);
    }
   
$rows[] = theme('workflow_history_table_row', $history, $old_state_name, $state_name);
  }

  print
theme('workflow_history_table', $rows, !empty($footer_needed));
  print
theme('pager', $states_per_page);

?>

#6

geerlingguy - October 21, 2009 - 07:55

I used your code above (with just the print workflow_tab_page($node);) to stick the workflow form in my node, and it seems to be working great - thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.