Download & Extend

Display the workflow in the node when viewing the node?

Project:Workflow
Version:6.x-1.1
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (works as designed)

Issue Summary

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

Comments

#1

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

#2

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

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

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

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

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!

#7

Where did you put this code to get the effect? Many Thanks, Jeff

#8

also looking forward to guide how to print the status of the node (view mode), to use it for theming. Thanks :)

#9

Just after the $content variable was printed...

#10

To display the current workflow state on my node, I did this in hook_nodeapi:

<?php
if ($op == 'view') {
 
$states = workflow_get_states(1);
 
$node->content['workflow_status'] = array(
   
'#weight' => 0,
   
'#value' => '<strong>' . t('Current State: ') . '</strong>' . $states[$node->_workflow],
  );
}
?>

(Where I happen to know "1" is the workflow id.)

#11

Hi,

Might be hijacking this a little - I am using views to basically show all the previous history of the workflow on the node itself which all users get to see and this works great, but would be really like to have the edit/add workflow widget above that so it looks like its part of the node, of course, only those with permissions will see it.

I am not 100% comfortable with messing around with all this php - is this the best way to achieve what I want to do?

Thanks,
Paul.

#12

@greyside

Thanks for your help!
Unfortunately I am a greenhorn... can you help my out with a step by step guide where to place this?
doe this go somewhere in template.php?

#13

<?php
// node.tpl.php
module_load_include('inc', 'workflow', 'workflow.pages');
$workflow_rendered = workflow_tab_page($node);
?>

#14

@yanku #12:

That code calls for writing a custom module. Most complex Drupal sites have a custom module for one-off customizations, and that usually includes an implementation of hook_nodeapi().

My code above would go in a custom_module.module file, and be wrapped in:

<?php
/**
* Implementation of hook_nodeapi().
*/
function custom_module_nodeapi(&$node, $op, $a3, $a4) {
 
// code from #10
}
?>

#15

hi to all! i put the code above in number #13 (to view the tab workflow into the node page), in my node.tpl.php and when i click submit ( to change the state ) the content is printed again so figures twice content of my node. If i submit again,adds to the content and i have three content printed. it´s like to $content add $content again. The content of workflow tab page it´s perfect.
My code is :

<?php
print $content ;
          
module_load_include('inc', 'workflow', 'workflow.pages');
           print
'<hr />';
           print
workflow_tab_page($node);
       
?>

Anyone knows why?, or how i can fix it?,

Thanks in advance,

Nicolas.

EDIT: i solve this problem changing in my tlp.php:
removing print $content ;
adding each field like this:
print $field_namefield1_rendered;
print $field_namefield2_rendered;
print $field_namefield3_rendered;
i don´t know why it happens, what´s the difference?, ( i print all the fields that has $content.).

#16

subscribing

#17

Status:active» closed (works as designed)

Under your workflow edit page you should see the option to display the form to change workflow in the node or with the comment.

Otherwise, if you're looking just to display the history, then hook nodeapi in a custom module or template work in node.tpl.php as described above is the best way to go about adding anything more to the node display.

#18

I'm experiencing the same issue as #15. If I add the state change form to the node template using the same code as #15 (or printing workflow_extensions_change_state_form($node) from the Workflow Extensions module), the node's body field gets loaded with all my CCK field data.

Each time I change the state, it adds that same data again. So if I change the state 3 times, the cck data will show up 3 times in $node->content['body']['#value']. Checking the node_revisions table shows the data is being stored in the body column.

I disabled all non-core modules and used Garland theme to test and still had the same issue.

nobody click here