? 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 .= '

' . t("%role may do these transitions:", array('%role' => $role)) . '

'; + $output .= '

'. t("%role may do these transitions:", array('%role' => $role)) .'

'; if ($rows) { $output .= theme('table', $header, $rows); } @@ -608,14 +610,25 @@ function workflow_permissions($wid) { * HTML form. * */ -function workflow_edit($wid) { -// $name = workflow_get_name($wid); +function workflow_edit_page($wid) { + $output = drupal_get_form('workflow_edit_form', $wid); + $output .= workflow_permissions($wid); + return $output; +} + +function workflow_edit_form($wid) { + $form = array(); + #$form['#theme'] = 'workflow_edit_form'; + $workflow = db_fetch_object(db_query("SELECT * FROM {workflows} WHERE wid = %d", $wid)); + $form['wid'] = array( + '#type' => 'value', + '#value' => $workflow->wid + ); $form['wf_name'] = array( '#type' => 'textfield', '#default_value' => $workflow->name, '#title' => t('Workflow Name'), - '#size' => '16', '#maxlength' => '254', ); $form['tab'] = array( @@ -624,7 +637,6 @@ function workflow_edit($wid) { '#collapsible' => TRUE, '#collapsed' => FALSE, ); - $form['tab']['tab_roles'] = array( '#type' => 'checkboxes', '#options' => workflow_get_roles(), @@ -632,19 +644,19 @@ function workflow_edit($wid) { '#description' => t('Select any roles that should have access to the workflow tab on nodes that have a workflow.'), ); - $form['transitions'] = workflow_transition_grid_form($wid); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); - $form['wid'] = array('#type' => 'value', '#value' => $wid); - $form['#theme'] = 'workflow_edit'; + $form['transitions'] = workflow_transition_grid_form($workflow->wid); $form['transitions']['#tree'] = TRUE; - $output = drupal_get_form('workflow_edit', $form); - $output .= workflow_permissions($wid); - return $output; + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save') + ); + + return $form; } -function theme_workflow_edit($form) { - $output = form_render($form['wf_name']); +function theme_workflow_edit_form($form) { + $output = drupal_render($form['wf_name']); $wid = $form['wid']['#value']; $states = workflow_get_states($wid); if ($states) { @@ -666,8 +678,8 @@ function theme_workflow_edit($form) { $to = $nested_state_id; $cell = ''; foreach ($roles as $rid => $role_name) { - $cell .= form_render($form['transitions'][$from][$to][$rid]); - //$cell .= form_render($form['transitions']["transitions][$from][$to][$rid"]); + $cell .= drupal_render($form['transitions'][$from][$to][$rid]); + //$cell .= drupal_render($form['transitions']["transitions][$from][$to][$rid"]); } $row[] = array('data' => $cell); } @@ -682,11 +694,11 @@ function theme_workflow_edit($form) { $output = 'There are no states defined for this workflow.'; } - $output .= form_render($form); + $output .= drupal_render($form); return $output; } -function workflow_edit_validate($form_id, $form_values) { +function workflow_edit_form_validate($form_id, $form_values) { $wid = $form_values['wid']; if (array_key_exists('wf_name', $form_values) && $form_values['wf_name'] != '') { // validate: make sure workflow name is not a duplicate @@ -714,11 +726,11 @@ function workflow_edit_validate($form_id } } -function workflow_edit_submit($form_id, $form_values) { +function workflow_edit_form_submit($form_id, $form_values) { workflow_update($form_values['wid'], $form_values['wf_name'], array_filter($form_values['tab_roles'])); workflow_update_transitions($form_values['transitions']); drupal_set_message(t('Workflow updated.')); - return('admin/workflow'); + return('admin/build/workflow'); } /** @@ -731,7 +743,7 @@ function workflow_edit_submit($form_id, * HTML form. * */ -function workflow_state_add ($wid) { +function workflow_state_add_form($wid) { $form['state_name'] = array( '#type' => 'textfield', '#title' => t('State Name'), @@ -740,20 +752,19 @@ function workflow_state_add ($wid) { ); $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); $form['wid'] = array('#type' => 'value', '#value' => $wid); - $output = drupal_get_form('workflow_state_add', $form); - return $output; + return $form; } -function workflow_state_add_validate($form_id, $form_values) { +function workflow_state_add_form_validate($form_id, $form_values) { if ($form_values['state_name'] == '') { form_set_error('', t('Please provide a nonblank name for the new state.')); } } -function workflow_state_add_submit($form_id, $form_values) { +function workflow_state_add_form_submit($form_id, $form_values) { workflow_state_create($form_values['wid'], $form_values['state_name']); drupal_set_message(t('The workflow state was created.')); - return('admin/workflow'); + return('admin/build/workflow'); } /** @@ -835,13 +846,15 @@ function workflow_transition_delete_role * @param int $wid */ function workflow_transition_grid_form($wid) { + $form = array(); $roles = workflow_get_roles(); - - $form = array(); $states = workflow_get_states($wid); if (!$states) { - $form = array('#type' => 'markup', '#value' => t('There are no states defined for this workflow.')); + $form = array( + '#type' => 'markup', + '#value' => t('There are no states defined for this workflow.') + ); return $form; } foreach ($states as $state_id => $name) { @@ -895,39 +908,56 @@ function workflow_transition_allowed($ti * */ function workflow_overview() { - $result = db_query("SELECT * FROM {workflows}"); - $header = array(array('data' => t('Name')), array('data' => 'Operations', 'colspan' => '4')); + $result = db_query("SELECT wid, name FROM {workflows}"); $row = array(); - while ($data = db_fetch_object($result)) { + $links = array( + 'workflow_overview_add_state' => array( + 'title' => t('Add state'), + 'href' => "admin/build/workflow/state/$data->wid"), + 'workflow_overview_actions' => array( + 'title' => t('Actions'), + 'href' => "admin/build/workflow/actions/$data->wid"), + 'workflow_overview_edit' => array( + 'title' => t('Edit'), + 'href' => "admin/build/workflow/edit/$data->wid"), + 'workflow_overview_delete' => array( + 'title' => t('Delete'), + 'href' => "admin/build/workflow/delete/$data->wid"), + ); + $states = workflow_get_states($data->wid); - $row[] = array( - array('data' => $data->name), - array('data' => l(t('add state'), "admin/workflow/state/$data->wid")), - array('data' => $states && module_exist('actions') ? l(t('actions'), "admin/workflow/actions/$data->wid") : ''), - array('data' => l(t('edit'), "admin/workflow/edit/$data->wid")), - array('data' => l(t('delete'), "admin/workflow/delete/$data->wid"))); + if (!(module_exists('actions') && $states)) { + unset($links['workflow_overview_actions']); + } + $row[] = array($data->name, theme('links', $links)); if ($states) { - $cell = ''; + $subrows = array(); foreach ($states as $sid => $state) { if (!workflow_is_system_state($state)) { - $cell .= "
" . $state; - $cell .= ""; - $cell .= l(t('delete'), "admin/workflow/delete/$data->wid/$sid") . "
"; + $statelinks = array( + 'workflow_overview_delete_state' => array( + 'title' => t('Delete'), + 'href' => "admin/build/workflow/delete/$data->wid/$sid" + ), + ); + $subrows[] = array($state, theme('links', $statelinks)); } } - $row[] = array(array('data' => $cell, 'colspan' => '5')); + $cell = theme('table', array(t('State'), t('Operations')), $subrows, array('style' => 'width: 100%;')); + $row[] = array(array('data' => $cell, 'colspan' => '2')); } } - if (!$row) { - $output = '

' . 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 = '
' . t('Each node type may have a separate workflow:') . '
'; - $header = array( - array('data' => t('Node Type')), - array('data' => t('Workflow')) - ); + $header = array(t('Node Type'), t('Workflow')); $row = array(); foreach (element_children($form) as $key) { - $name = $form[$key]['#prefix']; - unset($form[$key]['#prefix']); - $row[] = array( - array('data' => $name), - array('data' => form_render($form[$key])) - ); + if ($form[$key]['#type'] == 'select') { + $name = $form[$key]['#title']; + unset($form[$key]['#title']); + $row[] = array($name, drupal_render($form[$key])); + } } + $output = drupal_render($form['help']); $output .= theme('table', $header, $row); - return $output; + return $output . drupal_render($form); } -function workflow_type_form_submit($form_id, $form_values) { +function workflow_types_form_submit($form_id, $form_values) { workflow_types_save($form_values); drupal_set_message(t('The workflow mapping was saved.')); - return('admin/workflow'); + return('admin/build/workflow'); } function workflow_actions_remove_form($wid, $tid, $aid) { @@ -1044,7 +1079,14 @@ function workflow_actions_remove_form($w $form['tid'] = array('#type' => 'value', '#value' => $tid); $form['aid'] = array('#type' => 'value', '#value' => $aid); $actions = actions_get_all_actions(); - $output = confirm_form('workflow_actions_remove_confirm', $form, t('Are you sure you want to delete the action %title?', array('%title' => theme('placeholder', $actions[$aid]['description']))), $_GET['destination'] ? $_GET['destination'] : 'admin/workflow/actions', t('You can add it again later if you wish.'), t('Delete'), t('Cancel') ); + $output = confirm_form( + $form, + t('Are you sure you want to delete the action %title?', array('%title' => $actions[$aid]['description'])), + $_GET['destination'] ? $_GET['destination'] : 'admin/build/workflow/actions/'. $wid, + t('You can add it again later if you wish.'), + t('Delete'), + t('Cancel') + ); return $output; } @@ -1059,116 +1101,114 @@ function workflow_actions_remove_confirm } } -function workflow_actions_form($wid) { - if (!module_exist('actions')) { +function workflow_actions_page($wid) { + if (!module_exists('actions')) { drupal_set_message(t('Before you can assign actions you must install and enable the actions module.'), 'error'); - drupal_goto('admin/workflow'); + drupal_goto('admin/build/workflow'); } - $result = workflow_actions_form_build($wid); - $form = $result[1]; - $output = workflow_actions_form_build($wid, $form); - return $output[0]; -} -function workflow_actions_submit($form, $form_values) { - $tid = $form_values['tid']; - $aid = actions_key_lookup($form_values['action']); - workflow_actions_save($tid, $aid); - - // the form does weird things if we don't do a drupal_goto() - $wid = arg(3); - return("admin/workflow/actions/$wid"); -} - -function workflow_actions_form_build($wid, $form = NULL) { - if (!isset($form)) { - $form = array(); - $render = FALSE; - } - else { - $render =TRUE; - } - $output = ''; - $states = array(); - $all_states = workflow_get_states($wid); - - foreach ($all_states as $key => $val) { - $states[$key] = $val; - } - - $actions = actions_actions_map(actions_get_all_actions()); $options = array(t('None')); - foreach ($actions as $aid => $action) { + foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) { $options[$aid] = $action['description']; } + $header = array( array('data' => t('Transition'), 'colspan' => '3'), array('data' => t('Actions')) - ); - $row = array(); + ); + $rows = array(); + $states = workflow_get_states($wid); foreach ($states as $sid => $state) { - - $allowable_to = workflow_allowable_transitions($sid); - $actions_this_tid = array(); - // we'll create a row for each allowable transition + $allowable_to = workflow_allowable_transitions($sid); foreach ($allowable_to as $to_sid => $name) { - $inner_row = array(); $tid = workflow_get_transition_id($sid, $to_sid); - // get and list the actions that are already assigned to this transition - $actions_this_tid = workflow_get_actions($tid); - $available_options = $options; - foreach ($actions_this_tid as $aid => $act_name) { - $inner_row[] = array( - array('data' => $act_name), - array('data' => l(t('remove'), "admin/workflow/actions/remove/$wid/$tid/$aid")) - ); - unset($available_options[$aid]); - } - - // list possible actions that may be assigned - if (count($available_options) > 1) { - if ($render) { - $inner_row[] = array( - array('data' => drupal_get_form('workflow_actions_'. $tid, $form[$tid], 'workflow_actions'), 'colspan' => '2')); - } - else { - $form[$tid] = array(); - $form[$tid]['action'] = array( - '#prefix' => '', - '#type' => 'select', - '#options' => $available_options, - '#default_value' => t('None') - ); - $form[$tid]['submit'] = array( - '#prefix' => '
', - '#suffix' => '', - '#suffix' => '
', - '#type' => 'submit', - '#value' => t('Add') - ); - $form[$tid]['tid'] = array('#type' => 'value', '#value' => $tid); - } - } - $action_table = theme('table', array(), $inner_row); - $row[] = array( + $rows[] = array( array('data' => $state), array('data' => WORKFLOW_ARROW), array('data' => $name), - array('data' => $action_table) - ); + array('data' => drupal_get_form('workflow_actions_form', $wid, $tid, $options)) + ); } } - if (count($row) == 0) { - $output .= t('You must first %link before you can assign actions.', array('%link' => l(t('set up transitions'), 'admin/workflow/edit/' . $wid))); + if (count($rows) == 0) { + $output = t('You must first set up transitions before you can assign actions.', array('@link' => url('admin/build/workflow/edit/' . $wid))); } else { - $output .= theme('table', $header, $row); + $output = theme('table', $header, $rows); } - return array($output, $form); + return $output; +} + +function workflow_actions_form($wid, $tid, $available_options) { + $form['tid'] = array( + '#type' => 'value', + '#value' => $tid + ); + // get and list the actions that are already assigned to this transition + $actions_this_tid = workflow_get_actions($tid); + foreach ($actions_this_tid as $aid => $act_name) { + $form['remove'][$aid] = array( + '#type' => 'item', + '#title' => $act_name, + '#value' => l(t('remove'), "admin/build/workflow/actions/remove/$wid/$tid/$aid"), + ); + unset($available_options[md5($aid)]); + } + + // list possible actions that may be assigned + if (count($available_options) > 1) { + $form['action'] = array( + '#type' => 'select', + '#options' => $available_options, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Add') + ); + } + return $form; +} + +function theme_workflow_actions_form($form) { + $row = array(); + // put each existing action and remove link on it's own row + foreach (element_children($form['remove']) as $key) { + $name = $form['remove'][$key]['#title']; + unset($form['remove'][$key]['#title']); + $row[] = array($name, drupal_render($form['remove'][$key])); + } + // and if there are form items for a "new" action put that on a row + if (isset($form['action'])) { + $row[] = array(drupal_render($form['action']), drupal_render($form['submit'])); + } + $output .= theme('table', array(), $row); + return $output . drupal_render($form); +} + +function workflow_actions_form_submit($form, $form_values) { + $tid = $form_values['tid']; + $aid = actions_key_lookup($form_values['action']); + workflow_actions_save($tid, $aid); + + // the form does weird things if we don't do a drupal_goto() + $wid = arg(4); + return "admin/build/workflow/actions/$wid"; +} + +function workflow_actions_remove_form_submit($form_id, $form_values) { + if ($form_values['confirm'] == 1) { + $aid = $form_values['aid']; + $actions = actions_get_all_actions(); + $action = $actions[$aid]['description']; + workflow_actions_remove($form_values['tid'], $aid); + watchdog('workflow', t('Action %action deleted', array('%action' => $action))); + drupal_set_message(t('Action %action deleted.', array('%action' => $action))); + } + return 'admin/build/workflow/actions/'. $form_values['wid']; } /** @@ -1596,4 +1636,4 @@ function workflow_handler_arg_sid($op, & $state = db_fetch_object(db_query("SELECT state FROM {workflow_states} WHERE sid=%d", $query)); return $state->state; } -} \ No newline at end of file +}