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

stodge’s picture

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

dawansv’s picture

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).

      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...

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.

dman’s picture

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!

dawansv’s picture

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.

Anonymous’s picture

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);

?>
geerlingguy’s picture

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!

jhendricks47’s picture

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

stefan81’s picture

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

geerlingguy’s picture

Just after the $content variable was printed...

Grayside’s picture

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

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.)

techypaul’s picture

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.

stefan81’s picture

@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?

pendashteh’s picture

// node.tpl.php
module_load_include('inc', 'workflow', 'workflow.pages');
$workflow_rendered = workflow_tab_page($node);
Grayside’s picture

@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:

/**
 * Implementation of hook_nodeapi().
 */
function custom_module_nodeapi(&$node, $op, $a3, $a4) {
  // code from #10
}
nicostabile’s picture

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 :

 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.).

Encarte’s picture

subscribing

Bastlynn’s picture

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.

clockwood’s picture

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.

woibekwe’s picture

Version: 6.x-1.1 » 7.x-1.x-dev

Hello All,

The code solutions above are not working form me. I don't know if it is because im using 7.1 for Developers or because I am putting the code in the wrong place, but the workflow data does not show up on the view tab. Am I suppose to put the current solutions in node.tpl.php? If so where in that file am I suppose to put it? When I was debugging the view page I noticed that the node.tpl.php does not even get called when I click on the view tab link. If node.tpl.php is not where I put the the source solution there where would I put it?

Thank you fro all your help?

-Will

SOLUTION: I fixed it! I was editing the node.tpl.php in the node module not the template.

louis delacretaz’s picture

the code at #10 can be simplified by calling workflow_get_state_name instead as in

<?php
if (($op == 'view') && ($node->_workflow)) {
  $node->content['workflow_status'] = array(
    '#weight' => 0,
    '#value' => '<strong>' . t('Current State: ') . '</strong>' . workflow_get_state_name[$node->_workflow],
  );
}
?>
davidwhthomas’s picture

Not sure why this is closed as designed, quite useful to show the current workflow state on the node view page.

Ideally would be done with hook_field_extra_fields, but I adjusted the snippet in #20 for D7

/**
 * Implements hook_node_view
 */
function EXAMPLE_node_view($node){

  // Add current workflow state to node view
  if ($current = workflow_node_current_state($node)) {

    $workflow = workflow_get_workflow_type_map_by_type($node->type);
    foreach (workflow_get_workflow_states() as $data) {
      $states[$data->sid] = check_plain(t($data->state));
    }
    
    $node->content['workflow_status'] = array(
      '#weight' => 0,
      '#markup' => t('<strong>Current state:</strong> !state', array('!state' => $states[$current])),
    );
    
  }

}

Cheers,

DT

anjjriit’s picture

This is my compilation from all of you :
combined workflow page and form in node page

      case 'view':
			    include 'sites/all/modules/workflow/workflow.pages.inc';
			    $output = $node->content['body']['#value'];
			    $output .= '<hr />';
			    $output .= strstr(workflow_tab_page($node),'<table');
			    $output .= '<hr />';
			    $output .= 'Forkflow form';
			    $output .= workflow_extensions_change_state_form($node);
			    
			    $node->content['body']['#value'] = $output;
      break;
nancydru’s picture

I don't understand "useful to show the current workflow state on the node view page." The module does that already - no mods needed.

maximpodorov’s picture

Status: Closed (works as designed) » Active

@NancyDru
But it does it on 'full' view mode only! This is the problem.

function workflow_node_view($node, $view_mode, $langcode) {
  if ($view_mode != 'full' || !user_access('show workflow state form') || $node->status == 0) {
    return;
  }
...
}
andypost’s picture

this needs displayed via extra fields but should care about view mode settings

nancydru’s picture

Status: Active » Fixed

You are correct. Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mchaplin’s picture

Issue summary: View changes

The workflow form won't show on the node if it is unpublished.

https://drupal.org/node/2164081