? workflow-temp.patch ? workflow_5.0.patch Index: workflow.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.module,v retrieving revision 1.53 diff -u -p -r1.53 workflow.module --- workflow.module 28 Jan 2007 01:14:23 -0000 1.53 +++ workflow.module 1 Feb 2007 20:06:03 -0000 @@ -9,16 +9,14 @@ define('WORKFLOW_ARROW', '→'); */ function workflow_help($section) { switch ($section) { - case 'admin/modules#description': - return t('Enables users to manage content using workflow states.'); - case strstr($section, 'admin/workflow/edit'): + case strstr($section, 'admin/build/workflow/edit'): return t('You are currently viewing the possible transitions to and from workflow states. The state is shown in the left column; the state to be moved to is to the right. For each transition, check the box next to the role(s) that may initiate the transition. For example, if only the hulking_editor role may move a node from Review state to the Published state, check the box next to hulking_editor. The author role is built in and refers to the user who authored the node.'); - case 'admin/workflow/add': + case 'admin/build/workflow/add': return t('To get started, provide a name for your workflow. This name will be used as a label when the workflow status is shown during node editing.'); - case strstr($section, 'admin/workflow/state'): + case strstr($section, 'admin/build/workflow/state'): return t('Enter the name for a state in your workflow. For example, if you were doing a meal workflow it may include states like shop, prepare food, eat, and clean up.'); - case strstr($section, 'admin/workflow/actions') && (sizeof($section) == 22): - return t('Use this page to set actions to happen when transitions occur. To %conf_actions, use the actions module.', array('%conf_actions' => l('configure actions', 'admin/actions'))); + case strstr($section, 'admin/build/workflow/actions') && (sizeof($section) == 22): + return t('Use this page to set actions to happen when transitions occur. To configure actions, use the actions module.', array('@link' => url('admin/actions'))); } } @@ -37,54 +35,52 @@ function workflow_menu($may_cache) { $access = user_access('administer workflow'); if ($may_cache) { - $items[] = array('path' => 'admin/workflow', - 'title' => t('workflow'), + $items[] = array('path' => 'admin/build/workflow', + 'title' => t('Workflow'), 'access' => $access, - 'callback' => 'workflow_overview'); + 'callback' => 'workflow_overview', + 'description' => t('Allows the creation and assignment of arbitrary workflows to node types.')); - $items[] = array('path' => 'admin/workflow/edit', + $items[] = array('path' => 'admin/build/workflow/edit', 'title' => t('Edit workflow'), - 'access' => $access, 'type' => MENU_CALLBACK, - 'callback' => 'workflow_edit'); + 'callback' => 'workflow_edit_page'); - $items[] = array('path' => 'admin/workflow/list', + $items[] = array('path' => 'admin/build/workflow/list', 'title' => t('List'), - 'access' => $access, 'weight' => -10, 'callback' => 'workflow_page', 'type' => MENU_DEFAULT_LOCAL_TASK); - $items[] = array('path' => 'admin/workflow/add', + $items[] = array('path' => 'admin/build/workflow/add', 'title' => t('Add workflow'), - 'access' => $access, 'weight' => -8, - 'callback' => 'workflow_add_form', + 'callback' => 'drupal_get_form', + 'callback arguments' => array('workflow_add_form'), 'type' => MENU_LOCAL_TASK); - $items[] = array('path' => 'admin/workflow/state', + $items[] = array('path' => 'admin/build/workflow/state', 'title' => t('Add state'), - 'access' => $access, 'type' => MENU_CALLBACK, - 'callback' => 'workflow_state_add'); + 'callback' => 'drupal_get_form', + 'callback arguments' => array('workflow_state_add_form')); - $items[] = array('path' => 'admin/workflow/delete', + $items[] = array('path' => 'admin/build/workflow/delete', 'title' => t('Delete workflow'), - 'access' => $access, 'type' => MENU_CALLBACK, - 'callback' => 'workflow_delete'); + 'callback' => 'drupal_get_form', + 'callback arguments' => array('workflow_delete_form')); - $items[] = array('path' => 'admin/workflow/actions', + $items[] = array('path' => 'admin/build/workflow/actions', 'title' => t('Workflow actions'), - 'access' => $access, 'type' => MENU_CALLBACK, - 'callback' => 'workflow_actions_form'); + 'callback' => 'workflow_actions_page'); - $items[] = array('path' => 'admin/workflow/actions/remove', + $items[] = array('path' => 'admin/build/workflow/actions/remove', 'title' => t('Workflow actions'), - 'access' => $access, 'type' => MENU_CALLBACK, - 'callback' => 'workflow_actions_remove_form'); + 'callback' => 'drupal_get_form', + 'callback arguments' => array('workflow_actions_remove_form')); } else { if (arg(0) == 'node' && is_numeric(arg(1))) { @@ -99,19 +95,34 @@ function workflow_menu($may_cache) { $workflow = db_fetch_object(db_query("SELECT * FROM {workflows} WHERE wid = %d", $wid)); $allowed_roles = $workflow->tab_roles ? explode(',', $workflow->tab_roles) : array(); $items[] = array('path' => "node/$node->nid/workflow", - 'title' => t('workflow'), + 'title' => t('Workflow'), 'access' => array_intersect($roles, $allowed_roles) || user_access('administer nodes'), 'type' => MENU_LOCAL_TASK, 'weight' => 2, - 'callback' => 'workflow_tab_page', + 'callback' => 'workflow_tab_page', 'callback arguments' => arg(1), - ); + ); } } } return $items; } +function workflow_tab_form($values,$node,$name,$current,$choices) { + $form = array(); + workflow_node_form($form, t('Change %s state', array('%s' => $name)), $name, $current, $choices); + $form['node'] = array( + '#type' => 'value', + '#value' => $node, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} + function workflow_tab_page($nid) { drupal_set_title(t('workflow')); $node = node_load($nid); @@ -120,7 +131,7 @@ function workflow_tab_page($nid) { $states = workflow_get_states($wid) + array(t('(creation)')); $current = workflow_node_current_state($node); - $output = '
'. t('Current state: %state', array('%state' => check_plain($states[$current]))) . "
\n"; + $output = ''. t('Current state: @state', array('@state' => $states[$current])) . "
\n"; $choices = workflow_field_choices($node); $min = $states[$current] == t('(creation)') ? 1 : 2; @@ -129,19 +140,7 @@ function workflow_tab_page($nid) { $wid = workflow_get_workflow_for_type($node->type); $name = check_plain(workflow_get_name($wid)); - $form = array(); - workflow_node_form($form, t('Change %s state', array('%s' => $name)), $name, $current, $choices); - $form['node'] = array( - '#type' => 'value', - '#value' => $node, - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - - $output .= drupal_get_form('workflow_tab', $form); + $output .= drupal_get_form('workflow_tab_form', $node,$name,$current,$choices); } $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 stamp DESC", $states_per_page, 0, NULL, $nid); @@ -149,13 +148,13 @@ function workflow_tab_page($nid) { while ($history = db_fetch_object($result)) { $rows[] = array( format_date($history->stamp), - check_plain($states[$history->old_sid]), - check_plain($states[$history->sid]), - theme('username', $history), + check_plain($states[$history->old_sid]), + check_plain($states[$history->sid]), + theme('username', $history), check_plain($history->comment) ); } - + $output .= theme('table', array(t('Date'), t('Old State'), t('New State'), t('By'), t('Comment')), $rows, array('class' => 'workflow_history'), t('Workflow History')); $output .= theme('pager', $states_per_page); return $output; @@ -186,7 +185,7 @@ function workflow_tab_submit($form_id, $ * view view view * submit submit * insert update - * + * */ function workflow_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { @@ -226,7 +225,7 @@ function workflow_nodeapi(&$node, $op, $ /** * Add the actual form widgets for workflow change to the passed in form. * - * @param array $form + * @param array $form * @param string $name * @param string $current * @param array $choices @@ -338,10 +337,9 @@ function workflow_execute_transition($no // Register state change with watchdog $state_name = db_result(db_query("SELECT state FROM {workflow_states} WHERE sid = %d", $sid)); - $type = check_plain(node_get_name($node->type)); //module_invoke($node->type, 'node_name', $node); - $state_name = check_plain($state_name); - watchdog('workflow', t('State of %type %node_title set to %state_name', array('%type' => $type, '%node_title' => theme('placeholder', $node->title), '%state_name' => $state_name)), WATCHDOG_NOTICE, l('view', $node->nid)); - + $type = node_get_types('name', $node->type); + watchdog('workflow', t('State of @type %node_title set to @state_name', array('@type' => $type, '%node_title' => $node->title, '@state_name' => $state_name)), WATCHDOG_NOTICE, l('view', $node->nid)); + // Notify modules that transition has occurred. Actions should take place // in response to this callback, not the previous one. module_invoke_all('workflow', 'transition post', $old_sid, $sid, $node); @@ -498,13 +496,12 @@ function workflow_add_form($name = NULL) $form['wf_name'] = array( '#type' => 'textfield', '#title' => t('Workflow Name'), - '#size' => '16', '#maxlength' => '254', '#default_value' => $name ); $form['submit'] = array('#type' => 'submit', '#value' => t('Add Workflow')); - $output = drupal_get_form('workflow_add_form', $form); - return $output; + + return $form; } function workflow_add_form_validate($form_id, $form_values) { @@ -518,7 +515,7 @@ function workflow_add_form_submit($form_ $wf_name = $form_values['wf_name']; workflow_create($wf_name); drupal_set_message(t('The workflow %wf was created. You should now add states to your workflow.', array('%wf' => theme('placeholder', $wf_name)))); - drupal_goto('admin/workflow'); + drupal_goto('admin/build/workflow'); } } @@ -532,24 +529,29 @@ function workflow_add_form_submit($form_ * HTML form. * */ -function workflow_delete($wid, $sid = NULL) { +function workflow_delete_form($wid, $sid = NULL) { if (isset($sid)) { - return workflow_state_delete_form($wid, $sid); + return drupal_get_form('workflow_state_delete_form', $wid, $sid); } - $wf = workflow_get_name($wid); $form = array(); $form['wid'] = array('#type' => 'value', '#value' => $wid); - $output = confirm_form('workflow_delete_confirm', $form, t('Are you sure you want to delete %title? All nodes that have a workflow state associated with this workflow will have those workflow states removed.', array('%title' => theme('placeholder', $wf))), $_GET['destination'] ? $_GET['destination'] : 'admin/workflow', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); - return $output; + return confirm_form( + $form, + t('Are you sure you want to delete %title? All nodes that have a workflow state associated with this workflow will have those workflow states removed.', array('%title' => workflow_get_name($wid))), + $_GET['destination'] ? $_GET['destination'] : 'admin/build/workflow', + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') + ); } -function workflow_delete_confirm_submit($form_id, $form_values) { +function workflow_delete_form_submit($form_id, $form_values) { if ($form_values['confirm'] == 1) { $wid = $form_values['wid']; $wf = workflow_get_name($wid); workflow_deletewf($wid); drupal_set_message(t('The workflow %wf was deleted.', array('%wf' => theme('placeholder', $wf)))); - drupal_goto('admin/workflow'); + drupal_goto('admin/build/workflow'); } } @@ -587,7 +589,7 @@ function workflow_permissions($wid) { list($from, $to) = $transition; $rows[] = array($states[$from], WORKFLOW_ARROW, $states[$to]); } - $output .= '" . $state; - $cell .= " | "; - $cell .= l(t('delete'), "admin/workflow/delete/$data->wid/$sid") . " |
' . t('No workflows have been added. Would you like to %add_a_workflow?', array('%add_a_workflow' => l(t('add a workflow'), 'admin/workflow/add'))) . '
'; - } else { - $output .= theme('table', $header, $row); + if ($row) { + $output = theme('table', array(t('Workflow'), t('Operations')), $row); + } + else { + $output = '' . t('No workflows have been added. Would you like to add a workflow?', array('@link' => url('admin/build/workflow/add'))) . '
'; } - $output .= workflow_types_form(); + $output .= drupal_get_form('workflow_types_form'); return $output; } @@ -967,75 +997,80 @@ function workflow_state_delete_form($wid $form = array(); $form['wid'] = array('#type' => 'value', '#value' => $wid); $form['sid'] = array('#type' => 'value', '#value' => $sid); - $output = confirm_form('workflow_state_delete_confirm', $form, t('Are you sure you want to delete %title (and all its transitions)?', array('%title' => theme('placeholder', $states[$sid]))), $_GET['destination'] ? $_GET['destination'] : 'admin/workflow', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); - return $output; + return confirm_form( + $form, + t('Are you sure you want to delete %title (and all its transitions)?', array('%title' => $states[$sid])), + $_GET['destination'] ? $_GET['destination'] : 'admin/build/workflow', + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') + ); } -function workflow_state_delete_confirm_submit($form_id, $form_values) { +function workflow_state_delete_form_submit($form_id, $form_values) { $states = workflow_get_states($form_values['wid']); $state = $states[$form_values['sid']]; if ($form_values['confirm'] == 1) { workflow_state_delete($form_values['sid']); - drupal_set_message(t('The workflow state %title was deleted.', array('%title' => theme('placeholder', $state)))); + drupal_set_message(t('The workflow state %title was deleted.', array('%title' => $state))); } - return('admin/workflow'); + return('admin/build/workflow'); } function workflow_types_form() { + $form = array(); + $workflows = workflow_get_all(); if (count($workflows) == 0) { - return ''; + return $form; } $workflows[0] = t('None'); - $form = array(); - $form['workflow_mapping'] = array(); - $form['workflow_mapping']['#theme'] = 'workflow_types_form'; $type_map = array(); - $result = db_query("SELECT * FROM {workflow_type_map}"); + $result = db_query("SELECT wid, type FROM {workflow_type_map}"); while ($data = db_fetch_object($result)) { $type_map[$data->type] = $data->wid; } - $options = $workflows; - $nodetypes = node_get_types(); - foreach ($nodetypes as $type => $name) { - $value = isset($type_map[$type]) ? $type_map[$type] : 0; - $form['workflow_mapping'][$type] = array( + $form['#theme'] = 'workflow_types_form'; + $form['help'] = array( + '#type' => 'item', + '#value' => t('Each node type may have a separate workflow:'), + ); + foreach (node_get_types() as $type => $node) { + $form[$type] = array( '#type' => 'select', - '#prefix' => $name, - '#options' => $options, - '#default_value' => $value - ); + '#title' => $node->name, + '#options' => $workflows, + '#default_value' => isset($type_map[$type]) ? $type_map[$type] : 0 + ); } - $form['workflow_mapping']['submit'] = array('#type' => 'submit', '#value' => t('Save Workflow Mapping')); - $form['nodetypes'] = array('#type' => 'value', '#value' => $nodetypes); - return drupal_get_form('workflow_type_form', $form); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save Workflow Mapping') + ); + return $form; } function theme_workflow_types_form($form) { - $output = '', - '#suffix' => ' | ', - '#type' => 'select', - '#options' => $available_options, - '#default_value' => t('None') - ); - $form[$tid]['submit'] = array( - '#prefix' => '', - '#suffix' => ' |