View source
<?php
define('MARK_STATE_IS_DELETED', '*');
function workflow_tab_page($node = NULL) {
drupal_set_title($node->title);
$entity = $node;
$entity_type = 'node';
$entity_bundle = $node->type;
$workflow = workflow_get_workflows_by_type($entity_bundle, $entity_type);
$states = $workflow
->getStates();
if ($workflow_item = $workflow
->getWorkflowItem()) {
$current_sid = workflow_node_current_state($entity, $entity_type, $workflow_item
->getField());
$field = $workflow_item
->getField();
$instance = $workflow_item
->getInstance();
$langcode = NULL;
$items[0]['value'] = $current_sid;
$display = array();
$form = workflowfield_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);
$output = drupal_render($form);
}
else {
$current_sid = workflow_node_current_state($entity, $entity_type, $field = array());
$name = $states[$current_sid]
->getName();
$label = $states[$current_sid]
->label();
$output = theme('workflow_current_state', array(
'state' => $label,
'state_system_name' => $name,
'sid' => $current_sid,
));
$form = drupal_get_form('workflow_tab_form', $node, $workflow, $states, $current_sid);
$output .= drupal_render($form);
}
$rows = array();
$current_themed = FALSE;
foreach (workflow_get_workflow_node_history_by_nid($node->nid) as $history) {
$old_state_name = $new_state_name = '';
$label = $name = '';
$history_state = isset($states[$history->sid]) ? $states[$history->sid] : 0;
if ($history_state != NULL) {
$name = $history_state
->getName();
$label = $history_state
->label();
}
if (!$history_state) {
$old_state_name = check_plain($label);
}
elseif ($history->sid == $current_sid && $history_state
->isActive() && !$current_themed) {
$new_state_name = theme('workflow_history_current_state', array(
'state_name' => $label,
'state_system_name' => $name,
'sid' => $history->sid,
));
$current_themed = TRUE;
}
elseif (!$history_state
->isActive()) {
$new_state_name = theme('workflow_deleted_state', array(
'state_name' => $label,
'state_system_name' => $name,
'sid' => $history->sid,
));
$footer_needed = TRUE;
}
else {
$new_state_name = check_plain($label);
}
$label = $name = MARK_STATE_IS_DELETED;
$history_state = $states[$history->old_sid];
if ($history_state != NULL) {
$name = $history_state
->getName();
$label = $history_state
->label();
}
if (!$history_state) {
$old_state_name = check_plain($label);
}
elseif (!$history_state
->isActive()) {
$old_state_name = theme('workflow_deleted_state', array(
'state_name' => $label,
'state_system_name' => $name,
'sid' => $history->old_sid,
));
$footer_needed = TRUE;
}
else {
$old_state_name = check_plain($label);
}
$variables = array(
'transition' => $history,
'history' => $history,
'old_sid' => $history->old_sid,
'sid' => $history->sid,
'uid' => $history->uid,
'old_state_name' => $old_state_name,
'state_name' => $new_state_name,
);
drupal_alter('workflow_history', $variables);
$rows[] = theme('workflow_history_table_row', $variables);
}
$rows[0]['class'][] = 'first';
$last = count($rows) - 1;
$rows[$last]['class'][] = 'last';
if ($rows) {
$output .= theme('workflow_history_table', array(
'rows' => $rows,
'footer' => !empty($footer_needed),
));
$output .= theme('pager', array(
'tags' => variable_get('workflow_states_per_page', 20),
));
}
return $output;
}
function theme_workflow_history_table_row($variables) {
$row = array();
$old_state_name = $variables['old_state_name'];
$state_name = $variables['state_name'];
$transition = $variables['transition'];
$account = user_load($transition->uid);
$row = array(
'data' => array(
array(
'data' => format_date($transition->stamp),
'class' => array(
'timestamp',
),
),
array(
'data' => $old_state_name,
'class' => array(
'previous-state-name',
),
),
array(
'data' => $state_name,
'class' => array(
'state-name',
),
),
array(
'data' => theme('username', array(
'account' => $account,
)),
'class' => array(
'user-name',
),
),
array(
'data' => filter_xss($transition->comment),
'class' => array(
'log-comment',
),
),
),
'class' => array(
'workflow_history_row',
),
);
if (!empty($variables['extra'])) {
$row['data'][] = $variables['extra'];
}
return $row;
}
function theme_workflow_history_table($variables) {
$rows = $variables['rows'];
$footer = $variables['footer'];
$headers = array(
t('Date'),
t('Old State'),
t('New State'),
t('By'),
t('Comment'),
);
$output = theme('table', array(
'header' => $headers,
'rows' => $rows,
'caption' => t('Workflow History'),
));
if ($footer) {
$output .= MARK_STATE_IS_DELETED . ' ' . t('State is no longer available.');
}
return $output;
}
function theme_workflow_history_current_state($variables) {
return check_plain(t($variables['state_name']));
}
function theme_workflow_deleted_state($variables) {
return check_plain(t($variables['state_name'])) . MARK_STATE_IS_DELETED;
}
function workflow_tab_form($form, $form_state, $node, $workflow, $states, $current_sid) {
if (workflow_tab_access($node) === FALSE) {
return;
}
if (is_numeric($workflow)) {
$workflow = Workflow::load($wid = $workflow);
}
$state = WorkflowState::load($current_sid);
$options = $state
->getOptions($entity_type = 'node', $node, $force = FALSE);
if (workflow_show_form($current_sid, $workflow, $options)) {
form_load_include($form_state, 'inc', 'workflow', 'workflow.pages');
$form['#tab'] = TRUE;
$name = t($workflow->name);
$form['#wf'] = $workflow;
$form['#choices'] = $options;
$form['#node'] = $node;
$timestamp = NULL;
$comment = NULL;
if (!empty($node->workflow_scheduled_timestamp) && !empty($node->workflow_scheduled_sid)) {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) {
$timezone = $user->timezone;
}
else {
$timezone = variable_get('date_default_timezone', 0);
}
$current_sid = $node->workflow_scheduled_sid;
$timestamp = $node->workflow_scheduled_timestamp;
$comment = $node->workflow_scheduled_comment;
}
workflow_node_form($form, $form_state, t('Change !name state', array(
'!name' => $name,
)), $name, $current_sid, $options, $timestamp, $comment);
$form['node'] = array(
'#type' => 'value',
'#value' => $node,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update workflow'),
);
}
return $form;
}
function workflow_tab_form_submit($form, &$form_state) {
$node = $form_state['values']['node'];
if (isset($form_state['values']['workflow'])) {
$node->workflow = $form_state['values']['workflow'];
$node->workflow_comment = isset($form_state['values']['workflow_comment']) ? $form_state['values']['workflow_comment'] : '';
if (!empty($form_state['values']['workflow_scheduled'])) {
$node->workflow_scheduled = $form_state['values']['workflow_scheduled'];
}
if (!empty($form_state['values']['workflow_scheduled_date'])) {
$node->workflow_scheduled_date = $form_state['values']['workflow_scheduled_date'];
}
if (!empty($form_state['values']['workflow_scheduled_hour'])) {
$node->workflow_scheduled_hour = $form_state['values']['workflow_scheduled_hour'];
}
if (!empty($form_state['values']['workflow_scheduled_timezone'])) {
$node->workflow_scheduled_timezone = $form_state['values']['workflow_scheduled_timezone'];
}
}
workflow_transition($node, $node->workflow);
}