0

I have a workflow system in my site using workflow module, and I need to print the node current state name as body class.

I did the same with user current role in template.php with this snippet:

function sattari_preprocess_html(&$vars) {
  foreach($vars['user']->roles as $role){
    $vars['classes_array'][] = 'role-' . drupal_html_class($role);
  }
}

I'd really appreciate your help.

1

you can use the same hook_preprocess_html() hook to add the node current workflow state name as body class. there is workflow module api workflow_node_current_state which will return the current ID of workflow state of a node. i am just providing pseudo code.

function mymodule_preprocess_html(&$variables) {
  // Compile a list of classes that are going to be applied to the body element.
  // This allows advanced theming based on context (home page, node of certain type, etc.).
  $current_state = workflow_node_current_state($node);
  $variables["classes_array"][] = $current_state;

}

As workflow_node_current_state return the state id, If you want current state name rather then current state id, then you can do one more query to get the state name with this state id.

  • I changed the $current_state to this and it worked: $current_state = workflow_node_current_state($node); Thanks a lot man – Sohail Aug 24 '14 at 12:33
1

I think once you get the node object in your preprocess function then you will be able to add the class. Body classes are only applied in template_preprocess_html so you can do the following,

function sattari_preprocess_html(&$vars) {
  // If on an individual node page, add the node type to body classes.
  if ($node = menu_get_object()) {
    // debug($node);
    // Change as per your node object values added by workflow module.
    $variables['classes_array'][] = drupal_html_class('node-status-' . $node->status);
  }
}

For more reference have a look at template_preprocess_html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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