| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: workflow_named_transitions.module,v 1.1 2008/09/08 15:31:51 deekayen Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 13 |
* |
* |
| 14 |
* @return array |
* @return array |
| 15 |
*/ |
*/ |
| 16 |
function workflow_named_transitions_menu($may_cache) { |
function workflow_named_transitions_menu() { |
| 17 |
$items = array(); |
$items = array(); |
| 18 |
|
|
| 19 |
if ($may_cache) { |
$items['admin/build/workflow/labels'] = array( |
| 20 |
|
'title' => 'Edit labels', |
| 21 |
$items[] = array( |
'access callback' => 'user_access', |
| 22 |
'path' => 'admin/build/workflow/labels', |
'access arguments' => array('administer workflow'), |
| 23 |
'title' => t('Edit labels'), |
'page callback' => 'workflow_named_transitions_edit_labels_page', |
| 24 |
'access' => user_access('administer workflow'), |
'type' => MENU_LOCAL_TASK |
| 25 |
'type' => MENU_LOCAL_TASK, |
); |
| 26 |
'callback' => 'workflow_named_transitions_edit_labels_page' |
$items['admin/build/workflow/labels/%'] = array( |
| 27 |
); |
'title' => 'Edit labels', |
| 28 |
} |
'access callback' => 'user_access', |
| 29 |
else { |
'access arguments' => array('administer workflow'), |
| 30 |
|
'page callback' => 'drupal_get_form', |
| 31 |
$workflow = arg(4); |
'page arguments' => array('workflow_named_transitions_edit_labels_form', 4), |
| 32 |
if (!empty($workflow)) { |
'type' => MENU_LOCAL_TASK |
| 33 |
$items[] = array( |
); |
|
'path' => 'admin/build/workflow/labels/'. arg(4), |
|
|
'title' => t('Edit labels'), |
|
|
'access' => user_access('administer workflow'), |
|
|
'type' => MENU_LOCAL_TASK, |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array('workflow_named_transitions_edit_labels_form', arg(4)) |
|
|
); |
|
|
} |
|
|
} |
|
| 34 |
|
|
| 35 |
return $items; |
return $items; |
| 36 |
} |
} |
| 45 |
$workflows = workflow_get_all(); |
$workflows = workflow_get_all(); |
| 46 |
|
|
| 47 |
foreach ($workflows as $workflow_id => $workflow_name) { |
foreach ($workflows as $workflow_id => $workflow_name) { |
| 48 |
$output .= '<br />'. l("Edit workflow '$workflow_name' labels", "admin/build/workflow/labels/$workflow_id"); |
$output .= '<br />'. l(t("Edit workflow '@workflow_name' labels", array('@workflow_name' => $workflow_name)), "admin/build/workflow/labels/$workflow_id"); |
| 49 |
} |
} |
| 50 |
|
|
| 51 |
return $output; |
return $output; |
| 58 |
* |
* |
| 59 |
* @return array |
* @return array |
| 60 |
*/ |
*/ |
| 61 |
function workflow_named_transitions_edit_labels_form($workflow) { |
function workflow_named_transitions_edit_labels_form($request, $workflow) { |
| 62 |
if (!is_numeric($workflow)) { |
if (!is_numeric($workflow)) { |
| 63 |
drupal_set_message(t('Improper worklow ID provided.'), 'error'); |
drupal_set_message(t('Improper worklow ID provided.'), 'error'); |
| 64 |
watchdog('workflow_named_transitions', t('Improper worklow ID provided.'), WATCHDOG_NOTICE); |
watchdog('workflow_named_transitions', 'Improper worklow ID provided.'); |
| 65 |
drupal_goto('admin/build/workflow/labels'); |
drupal_goto('admin/build/workflow/labels'); |
| 66 |
} |
} |
| 67 |
|
|
| 95 |
} |
} |
| 96 |
|
|
| 97 |
/** |
/** |
| 98 |
|
* Implementation of hook_theme(). |
| 99 |
|
* |
| 100 |
|
* @return unknown |
| 101 |
|
*/ |
| 102 |
|
function workflow_named_transitions_theme() { |
| 103 |
|
return array( |
| 104 |
|
'workflow_named_transitions_edit_labels_form' => array( |
| 105 |
|
'arguments' => array('form' => NULL) |
| 106 |
|
) |
| 107 |
|
); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
/** |
| 111 |
* Formats the label form into two column table rows. The transition is |
* Formats the label form into two column table rows. The transition is |
| 112 |
* the first table cell, followed by the label field. Otherwise, the |
* the first table cell, followed by the label field. Otherwise, the |
| 113 |
* default display would be a form field with the transition as the FAPI |
* default display would be a form field with the transition as the FAPI |
| 121 |
// doing something with element_children() might be a better way |
// doing something with element_children() might be a better way |
| 122 |
// than this foreach looping methods |
// than this foreach looping methods |
| 123 |
foreach ($form as $starting_state => $transitions) { |
foreach ($form as $starting_state => $transitions) { |
| 124 |
if ($form[$starting_state]['#type'] == 'fieldset') { |
if (isset($form[$starting_state]['#type']) && $form[$starting_state]['#type'] == 'fieldset') { |
| 125 |
$rows = array(); |
$rows = array(); |
| 126 |
foreach ($transitions as $tid => $item) { |
foreach ($transitions as $tid => $item) { |
| 127 |
if (is_numeric($tid)) { |
if (is_numeric($tid)) { |
| 148 |
* |
* |
| 149 |
* @see workflow_named_transitions_edit_labels_form() |
* @see workflow_named_transitions_edit_labels_form() |
| 150 |
*/ |
*/ |
| 151 |
function workflow_named_transitions_edit_labels_form_submit($form_id, $form_values) { |
function workflow_named_transitions_edit_labels_form_submit($form, &$form_state) { |
| 152 |
foreach ($form_values as $tid => $label) { |
foreach ($form_state['values'] as $tid => $label) { |
| 153 |
if (!empty($tid) && $label != '') { |
if (!empty($tid) && $label != '') { |
| 154 |
db_query("REPLACE INTO {workflow_named_transitions} (tid, label) VALUES (%d, '%s')", $tid, $label, $tid, $label); |
db_query("REPLACE INTO {workflow_named_transitions} (tid, label) VALUES (%d, '%s')", $tid, $label, $tid, $label); |
| 155 |
} |
} |
| 189 |
* |
* |
| 190 |
* Modifies the generic state labels that the workflow module added to the form. |
* Modifies the generic state labels that the workflow module added to the form. |
| 191 |
*/ |
*/ |
| 192 |
function workflow_named_transitions_form_alter($form_id, &$form) { |
function workflow_named_transitions_form_alter(&$form, $form_state, $form_id) { |
| 193 |
|
|
| 194 |
|
|
| 195 |
if (isset($form['workflow']) && is_array($form['workflow'])) { |
if (isset($form['workflow']) && is_array($form['workflow'])) { |
| 196 |
// if no nid, use sysid == 1 from workflow_states for each wid |
// if no nid, use sysid == 1 from workflow_states for each wid |