1

There's a review content type on my site with a workflow: I use 'draft' and 'completed' workflow states.

I'd like to create a printer-friendly and pdf-version of 'finished' reviews only, so I'd like to hide the links generated by Print module in any other case. I tried to modify MYTHEME__preprocess_node() to achive this with this code, but it didn't work:

if($vars['field_review_workflow'][0]['value'] == '13'){ //sid of 'finished' state
  show($vars['elements']['links']['print_html']);
}else{
  hide($vars['elements']['links']['print_html']);
}

How could I do it properly?

3 Answers 3

2

One way of doing it is by using hook_node_view_alter(). For example, you would put the following code in a custom module called hideprint (see many tutorials online on how to create a custom module). Be sure to dpm() the array $build when you are testing the module to correctly check the value of field_review_workflow.

function hideprint_node_view_alter(&$build) {
  if ($build['field_review_workflow'][0]['#value'] == TYPE_VALUE_FOR_NOT_FINISHED){
    hide($build['links']['print_html']);
    hide($build['links']['print_pdf']);
  }    
}
1

There's a module for that! Workflow Fields

This module extends Workflow by allowing CCK node fields to be made invisible or read-only depending on the current workflow state. The workflow state form is extended to show all node fields with appropriate controls to hide and/or disable each field for that particular state.

This functionality is useful when a workflow moves among users who have different permissions regarding the document flowing through them. Which is the case in most every workflow we've encountered.

2
  • Thanks, but it's not a CCK field. The Print module adds links below the contet area.
    – StG
    Commented Oct 25, 2015 at 14:16
  • In that case you can use computed_field module and manually render print in a CCK field to be able to use this approach.
    – Sohail
    Commented Oct 25, 2015 at 16:41
1

After all, my approach has been proved to be useful too. Hiding of these links can be done in MYTHEME_preprocess_node() but content array should be used:

if($vars['field_review_workflow'][0]['value'] == '13'){ //sid of 'finished' state
  show($vars['content']['links']['print_html']);
}else{
  hide($vars['content']['links']['print_html']);
}

Anyways, thank you all for the input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.