workflow_admin_ui.page.labels.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Provides an Admin UI page for the Workflow Transition labels.
  5. *
  6. * Modify the workflow form items so specific workflow transitions
  7. * can have their own labels which the admin can describe relative
  8. * to the beginning and ending states.
  9. * Rather than showing the user a workflow box containing options like
  10. * "review required" as a state in the workflow, it could say "move to
  11. * the editing department for grammar review".
  12. *
  13. * AUTHOR
  14. * ------
  15. * David Kent Norman (http://deekayen.net/)
  16. *
  17. * Amazon Honor System donation:
  18. * http://zme.amazon.com/exec/varzea/pay/T2EOCSRRDQ9CL2
  19. *
  20. * Paypal donation:
  21. * https://www.paypal.com/us/cgi-bin/webscr?cmd=_xclick&business=paypal@deekayen.net&item_name=Drupal%20contribution&currency_code=USD&amount=20.00
  22. */
  23. /**
  24. * Label edit form, where each fieldset represents a starting workflow state.
  25. *
  26. * Each contains the transitions with that starting workflow state.
  27. *
  28. * @return array
  29. * Array of form items for editing labels on transitions.
  30. */
  31. function workflow_admin_ui_labels_form($form, &$form_state, $workflow, $op) {
  32. if (!is_object($workflow)) {
  33. drupal_set_message(t('Improper worklow ID provided.'), 'error');
  34. watchdog('workflow_named_transitions', 'Improper worklow ID provided.');
  35. drupal_goto(WORKFLOW_ADMIN_UI_PATH);
  36. }
  37. $headers = array(
  38. t('Transition from'),
  39. t('to'),
  40. t('label'),
  41. );
  42. $rows = array();
  43. $previous_from_sid = -1;
  44. // Get transitions, sorted by weight of the old state.
  45. $config_transitions = $workflow->getTransitions();
  46. foreach ($config_transitions as $transition) {
  47. $old_state = $transition->getOldState();
  48. $new_state = $transition->getNewState();
  49. $rows[] = array(
  50. 'data' => array(
  51. array('data' => (($previous_from_sid != $transition->sid) ? $old_state->label() : '"')),
  52. array('data' => $new_state->label()),
  53. array(
  54. 'data' => array(
  55. '#type' => 'textfield',
  56. '#value' => $transition->label(),
  57. '#size' => 60,
  58. '#maxlength' => 128,
  59. '#name' => 'label_' . $transition->tid,
  60. '#id' => 'label_' . $transition->tid,
  61. ),
  62. ),
  63. ),
  64. );
  65. $previous_from_sid = $transition->sid;
  66. }
  67. $form['transition_labels'] = array(
  68. '#theme' => 'table',
  69. '#header' => $headers,
  70. '#rows' => $rows,
  71. );
  72. // Save the transitions in the form to fetch upon submit.
  73. $form['#transitions'] = $config_transitions;
  74. $form['submit'] = array(
  75. '#type' => 'submit',
  76. '#value' => 'Submit',
  77. );
  78. return $form;
  79. }
  80. /**
  81. * Automatic submission handler for the Transition labels form.
  82. *
  83. * @see workflow_admin_ui_labels_form()
  84. */
  85. function workflow_admin_ui_labels_form_submit($form, &$form_state) {
  86. foreach ($form['#transitions'] as $config_transition) {
  87. $config_transition->label = trim($form_state['input']['label_' . $config_transition->tid]);
  88. $config_transition->save();
  89. }
  90. drupal_set_message(t('The transition labels have been saved.'));
  91. }