You are here

function workflow_node_view in Workflow 7

Implements hook_node_view().

Parameters

object $node.:

string $view_mode.:

string $langcode.:

Return value

renderable content in $node->content array.

File

./workflow.node.inc, line 184
Node specific functions, remnants of nodeapi.

Code

function workflow_node_view($node, $view_mode, $langcode) {
  if (!user_access('show workflow state form') || $node->status == 0) {
    return;
  }
  if (!($workflow = workflow_get_workflows_by_type($node->type))) {
    return;
  }
  $current_sid = workflow_node_current_state($node);
  $current_state = WorkflowState::load($current_sid);
  $choices = $current_state
    ->getOptions('node', $node);

  // Show current state at the top of the node display.
  $markup = theme('workflow_current_state', array(
    'state' => $current_state
      ->label(),
    'state_system_name' => $current_state
      ->getName(),
    'sid' => $current_state->sid,
  ));
  $node->content['workflow_current_state'] = array(
    '#markup' => $markup,
    '#weight' => -99,
  );
  if (workflow_show_form($current_sid, $workflow, $choices)) {
    $state_labels = $workflow
      ->getOptions();

    // Show state change form at the bottom of the node display.
    module_load_include('inc', 'workflow', 'workflow.pages');

    // By including the nid in the form id.
    $form = drupal_get_form("workflow_tab_form_{$node->nid}", $node, $workflow, $state_labels, $current_sid);
    $form['#weight'] = 99;
    $node->content['workflow'] = $form;
  }
}