source: sipes/modules_contrib/workflow/workflow.admin.inc @ 8a8efa8

stableversion-3.0
Last change on this file since 8a8efa8 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100644
File size: 24.3 KB
Línea 
1<?php
2// $Id: workflow.admin.inc,v 1.7.2.3 2010/03/15 04:22:48 jvandyk Exp $
3
4/**
5 * @file
6 * Administrative pages for configuring workflows.
7 */
8
9/**
10 * Form builder. Create the form for adding/editing a workflow.
11 *
12 * @param $name
13 *   Name of the workflow if editing.
14 * @param $add
15 *   Boolean, if true edit workflow name.
16 *
17 * @return
18 *   HTML form.
19 */
20function workflow_add_form(&$form_state, $name = NULL) {
21  $form = array();
22  $form['wf_name'] = array(
23    '#type' => 'textfield',
24    '#title' => t('Workflow Name'),
25    '#maxlength' => '254',
26    '#default_value' => $name
27  );
28  $form['submit'] = array(
29    '#type' => 'submit',
30    '#value' => t('Add Workflow')
31  );
32  return $form;
33}
34
35/**
36 * Validate the workflow add form.
37 *
38 * @see workflow_add_form()
39 */
40function workflow_add_form_validate($form, &$form_state) {
41  $workflow_name = $form_state['values']['wf_name'];
42  $workflows = array_flip(workflow_get_all());
43  // Make sure a nonblank workflow name is provided.
44  if ($workflow_name == '') {
45    form_set_error('wf_name', t('Please provide a nonblank name for the new workflow.'));
46  }
47  // Make sure workflow name is not a duplicate.
48  if (array_key_exists($workflow_name, $workflows)) {
49    form_set_error('wf_name', t('A workflow with the name %name already exists. Please enter another name for your new workflow.',
50      array('%name' => $workflow_name)));
51  }
52}
53
54/**
55 * Submit handler for the workflow add form.
56 *
57 * @see workflow_add_form()
58 */
59function workflow_add_form_submit($form, &$form_state) {
60  $workflow_name = $form_state['values']['wf_name'];
61  $wid = workflow_create($workflow_name);
62  watchdog('workflow', 'Created workflow %name', array('%name' => $workflow_name));
63  drupal_set_message(t('The workflow %name was created. You should now add states to your workflow.',
64    array('%name' => $workflow_name)), 'status');
65  $form_state['wid'] = $wid;
66  $form_state['redirect'] = 'admin/build/workflow/state/'. $wid;
67}
68
69/**
70 * Form builder. Create form for confirmation of workflow deletion.
71 *
72 * @param $wid
73 *   The ID of the workflow to delete.
74 * @return
75 *   Form definition array.
76 *
77 */
78function workflow_delete_form(&$form_state, $wid, $sid = NULL) {
79  if (isset($sid)) {
80    return workflow_state_delete_form($wid, $sid);
81  }
82  $form['wid'] = array(
83    '#type' => 'value',
84    '#value' => $wid
85  );
86  return confirm_form(
87    $form,
88    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))),
89    !empty($_GET['destination']) ? $_GET['destination'] : 'admin/build/workflow',
90    t('This action cannot be undone.'),
91    t('Delete'),
92    t('Cancel')
93  );
94}
95
96/**
97 * Submit handler for workflow deletion form.
98 *
99 * @see workflow_delete_form()
100 */
101function workflow_delete_form_submit($form, &$form_state) {
102  if ($form_state['values']['confirm'] == 1) {
103    $workflow_name = workflow_get_name($form_state['values']['wid']);
104    workflow_deletewf($form_state['values']['wid']);
105    watchdog('workflow', 'Deleted workflow %name with all its states', array('%name' => $workflow_name));
106    drupal_set_message(t('The workflow %name with all its states was deleted.', array('%name' => $workflow_name)));
107    $form_state['redirect'] = 'admin/build/workflow';
108  }
109}
110
111/**
112 * View workflow permissions by role
113 *
114 * @param $wid
115 *   The ID of the workflow.
116 */
117function workflow_permissions($wid) {
118  $name = workflow_get_name($wid);
119  $all = array();
120  $roles = array('author' => t('author')) + user_roles();
121  foreach ($roles as $role => $value) {
122    $all[$role]['name'] = $value;
123  }
124  $result = db_query(
125    'SELECT t.roles, s1.state AS state_name, s2.state AS target_state_name ' .
126    'FROM {workflow_transitions} t ' .
127    'INNER JOIN {workflow_states} s1 ON s1.sid = t.sid '.
128    'INNER JOIN {workflow_states} s2 ON s2.sid = t.target_sid '.
129    'WHERE s1.wid = %d ' .
130    'ORDER BY s1.weight ASC , s1.state ASC , s2.weight ASC , s2.state ASC',
131    $wid);
132
133  while ($data = db_fetch_object($result)) {
134    foreach (explode(',', $data->roles) as $role) {
135      $all[$role]['transitions'][] = array(check_plain(t($data->state_name)), WORKFLOW_ARROW, check_plain(t($data->target_state_name)));
136    }
137  }
138
139  $header = array(t('From'), '', t('To'));
140  return theme('workflow_permissions', $header, $all);
141}
142
143/**
144 * Theme the workflow permissions view.
145 */
146function theme_workflow_permissions($header, $all) {
147  $output = '';
148  foreach ($all as $role => $value) {
149    $output .= '<h3>'. t("%role may do these transitions:", array('%role' => $value['name'])) .'</h3>';
150    if (!empty($value['transitions'])) {
151      $output .= theme('table', $header, $value['transitions']) . '<p></p>';
152    }
153    else {
154      $output .= '<table><tbody><tr class="odd"><td>' . t('None') . '</td><td></tr></tbody></table><p></p>';
155    }
156  }
157
158  return $output;
159}
160
161/**
162 * Menu callback. Edit a workflow's properties.
163 *
164 * @param $wid
165 *   The ID of the workflow.
166 * @return
167 *   HTML form and permissions table.
168 */
169function workflow_edit_form($form_state, $workflow) {
170  $form['wid'] = array(
171    '#type' => 'value',
172    '#value' => $workflow->wid,
173  );
174  $form['basic'] = array(
175    '#type' => 'fieldset',
176    '#title' => t('Workflow information')
177  );
178  $form['basic']['wf_name'] = array(
179    '#type' => 'textfield',
180    '#default_value' => $workflow->name,
181    '#title' => t('Workflow Name'),
182    '#size' => '16',
183    '#maxlength' => '254',
184  );
185  $form['basic']['name_as_title'] = array(
186    '#type' => 'checkbox',
187    '#title' => t('Use the workflow name as the title of the workflow form.'),
188    '#default_value' => isset($workflow->options['name_as_title']) ? $workflow->options['name_as_title'] : 0,
189    '#description' => t('The workflow section of the editing form is in its own fieldset. Checking the box will add the workflow name as the title of workflow section of the editing form.'),
190  );
191  $form['comment'] = array(
192    '#type' => 'fieldset',
193    '#title' => t('Comment for Workflow Log'),
194  );
195  $form['comment']['comment_log_node'] = array(
196    '#type' => 'checkbox',
197    '#title' => t('Show a comment field in the workflow section of the editing form.'),
198    '#default_value' => $workflow->options['comment_log_node'],
199    '#description' => t("On the node editing form, a Comment form can be shown so that the person making the state change can record reasons for doing so. The comment is then included in the node's workflow history."),
200  );
201  $form['comment']['comment_log_tab'] = array(
202    '#type' => 'checkbox',
203    '#title' => t('Show a comment field in the workflow section of the workflow tab form.'),
204    '#default_value' => $workflow->options['comment_log_tab'],
205    '#description' => t("On the workflow tab, a Comment form can be shown so that the person making the state change can record reasons for doing so. The comment is then included in the node's workflow history."),
206  );
207  $form['tab'] = array(
208    '#type' => 'fieldset',
209    '#title' => t('Workflow tab permissions'),
210    '#collapsible' => TRUE,
211    '#collapsed' => FALSE,
212  );
213  $form['tab']['tab_roles'] = array(
214    '#type' => 'checkboxes',
215    '#options' => workflow_get_roles(),
216    '#default_value' => explode(',', $workflow->tab_roles),
217    '#description' => t('Select any roles that should have access to the workflow tab on nodes that have a workflow.'),
218  );
219
220  $form['transitions'] = workflow_transition_grid_form($workflow->wid);
221  $form['transitions']['#tree'] = TRUE;
222
223  $form['submit'] = array(
224    '#type' => 'submit',
225    '#value' => t('Save')
226  );
227
228  $form['permissions'] = array(
229    '#type' => 'fieldset',
230    '#title' => t('Permissions Summary'),
231    '#collapsible' => TRUE,
232  );
233  $form['permissions']['summary'] = array(
234    '#value' => workflow_permissions($workflow->wid),
235  );
236
237  return $form;
238}
239
240/**
241 * Theme the workflow editing form.
242 *
243 * @see workflow_edit_form()
244 */
245function theme_workflow_edit_form($form) {
246  $output = drupal_render($form['wf_name']);
247  $wid = $form['wid']['#value'];
248  $states = workflow_get_states($wid);
249  drupal_set_title(t('Edit workflow %name', array('%name' => workflow_get_name($wid))));
250  if ($states) {
251    $roles = workflow_get_roles();
252    $header = array(array('data' => t('From / To ') . '&nbsp;' . WORKFLOW_ARROW));
253    $rows = array();
254    foreach ($states as $state_id => $name) {
255      // Don't allow transition TO (creation).
256      if ($name != t('(creation)')) {
257        $header[] = array('data' => check_plain(t($name)));
258      }
259      $row = array(array('data' => check_plain(t($name))));
260      foreach ($states as $nested_state_id => $nested_name) {
261        if ($nested_name == t('(creation)')) {
262          // Don't allow transition TO (creation).
263          continue;
264        }
265        if ($nested_state_id != $state_id) {
266          // Need to render checkboxes for transition from $state to $nested_state.
267          $from = $state_id;
268          $to = $nested_state_id;
269          $cell = '';
270          foreach ($roles as $rid => $role_name) {
271            $cell .= drupal_render($form['transitions'][$from][$to][$rid]);
272          }
273          $row[] = array('data' => $cell);
274        }
275        else {
276          $row[] = array('data' => '');
277        }
278      }
279      $rows[] = $row;
280    }
281    $output .= theme('table', $header, $rows);
282
283  }
284  else {
285    $output = t('There are no states defined for this workflow.');
286  }
287
288  $output .= drupal_render($form);
289  return $output;
290}
291
292/**
293 * Validate the workflow editing form.
294 *
295 * @see workflow_edit_form()
296 */
297function workflow_edit_form_validate($form_id, $form_state) {
298  $wid = $form_state['values']['wid'];
299  // Make sure workflow name is not a duplicate.
300  if (array_key_exists('wf_name', $form_state['values']) && $form_state['values']['wf_name'] != '') {
301    $workflow_name = $form_state['values']['wf_name'];
302    $workflows = array_flip(workflow_get_all());
303    if (array_key_exists($workflow_name, $workflows) && $wid != $workflows[$workflow_name]) {
304      form_set_error('wf_name', t('A workflow with the name %name already exists. Please enter another name for this workflow.',
305        array('%name' => $workflow_name)));
306    }
307  }
308  else {
309  // No workflow name was provided.
310    form_set_error('wf_name', t('Please provide a nonblank name for this workflow.'));
311  }
312
313  // Make sure 'author' is checked for (creation) -> [something].
314  $creation_id = _workflow_creation_state($wid);
315  if (isset($form_state['values']['transitions'][$creation_id]) && is_array($form_state['values']['transitions'][$creation_id])) {
316    foreach ($form_state['values']['transitions'][$creation_id] as $to => $roles) {
317      if ($roles['author']) {
318        $author_has_permission = TRUE;
319        break;
320      }
321    }
322  }
323  $state_count = db_result(db_query("SELECT COUNT(sid) FROM {workflow_states} WHERE wid = %d", $wid));
324  if (empty($author_has_permission) && $state_count > 1) {
325    form_set_error('transitions', t('Please give the author permission to go from %creation to at least one state!',
326      array('%creation' => '(creation)')));
327  }
328}
329
330/**
331 * Submit handler for the workflow editing form.
332 *
333 * @see workflow_edit_form()
334 */
335function workflow_edit_form_submit($form, &$form_state) {
336  if (isset($form_state['values']['transitions'])) {
337    workflow_update_transitions($form_state['values']['transitions']);
338  }
339  $options = array(
340    'comment_log_node' => $form_state['values']['comment_log_node'],
341    'comment_log_tab' => $form_state['values']['comment_log_tab'],
342    'name_as_title' => $form_state['values']['name_as_title'],
343  );
344  workflow_update($form_state['values']['wid'], $form_state['values']['wf_name'], array_filter($form_state['values']['tab_roles']), $options);
345  drupal_set_message(t('The workflow was updated.'));
346  $form_state['redirect'] = 'admin/build/workflow';
347}
348
349/**
350 * Menu callback and form builder. Create form to add a workflow state.
351 *
352 * @param $wid
353 *   The ID of the workflow.
354 * @return
355 *   HTML form.
356 */
357function workflow_state_add_form(&$form_state, $wid, $sid = NULL) {
358  $form['wid'] = array('#type' => 'value', '#value' => $wid);
359
360  if (isset($sid)) {
361    $state = workflow_get_state($sid);
362    if (isset($state) && $state['status']) {
363      drupal_set_title(t('Edit workflow state %state', array('%state' => $state['state'])));
364      $form['sid'] = array(
365        '#type' => 'value',
366        '#value' => $sid
367      );
368    }
369  }
370
371  // If we don't have a state or db_fetch_array() returned FALSE, load defaults.
372  if (!isset($state) || $state === FALSE) {
373    $state = array('state' => '', 'weight' => 0);
374    drupal_set_title(t('Add a new state to workflow %workflow', array('%workflow' => workflow_get_name($wid))));
375  }
376
377  $form['state'] = array(
378    '#type'  => 'textfield',
379    '#title' => t('State name'),
380    '#default_value' => $state['state'],
381    '#size'  => '16',
382    '#maxlength' => '254',
383    '#required' => TRUE,
384    '#description' => t('Enter the name for a state in your workflow. For example, if you were doing a meal workflow it may include states like <em>shop</em>, <em>prepare</em>, <em>eat</em>, and <em>clean up</em>.'),
385  );
386  $form['weight'] = array(
387    '#type' => 'weight',
388    '#title' => t('Weight'),
389    '#default_value' => $state['weight'],
390    '#description' => t('In listings, the heavier states will sink and the lighter states will be positioned nearer the top.'),
391  );
392  $form['submit'] = array(
393    '#type' => 'submit',
394    '#value' => t('Save')
395  );
396  return $form;
397}
398
399/**
400 * Validate the state addition form.
401 *
402 * @see workflow_state_add_form()
403 */
404function workflow_state_add_form_validate($form, &$form_state) {
405  $state_name = $form_state['values']['state'];
406  $wf_states = array_flip(workflow_get_states($form_state['values']['wid']));
407  if (array_key_exists('sid', $form_state['values'])) {
408    // Validate changes to existing state:
409    // Make sure a nonblank state name is provided.
410    if ($state_name == '') {
411      form_set_error('state', t('Please provide a nonblank name for this state.'));
412    }
413    // Make sure changed state name is not a duplicate
414    if (array_key_exists($state_name, $wf_states) && $form_state['values']['sid'] != $wf_states[$state_name]) {
415      form_set_error('state', t('A state with the name %state already exists in this workflow. Please enter another name for this state.', array('%state' => $state_name)));
416    }
417  }
418  else {
419    // Validate new state:
420    // Make sure a nonblank state name is provided
421    if ($state_name == '') {
422      form_set_error('state', t('Please provide a nonblank name for the new state.'));
423    }
424    // Make sure state name is not a duplicate
425    if (array_key_exists($state_name, $wf_states)) {
426      form_set_error('state', t('A state with the name %state already exists in this workflow. Please enter another name for your new state.', array('%state' => $state_name)));
427    }
428  }
429}
430
431/**
432 * Submit handler for state addition form.
433 *
434 * @see workflow_state_add_form()
435 */
436function workflow_state_add_form_submit($form, &$form_state) {
437  $form_state['sid'] = workflow_state_save($form_state['values']);
438  if (array_key_exists('sid', $form_state['values'])) {
439    drupal_set_message(t('The workflow state was updated.'));
440  }
441  else {
442    watchdog('workflow', 'Created workflow state %name', array('%name' => $form_state['values']['state']));
443    drupal_set_message(t('The workflow state %name was created.', array('%name' => $form_state['values']['state'])));
444  }
445  $form_state['redirect'] = 'admin/build/workflow';
446}
447
448/**
449 * Form builder. Build the grid of transitions for defining a workflow.
450 *
451 * @param int $wid
452 *   The ID of the workflow.
453 */
454function workflow_transition_grid_form($wid) {
455  $form = array();
456
457  $roles = workflow_get_roles();
458  $states = workflow_get_states($wid);
459  if (!$states) {
460    $form = array(
461      '#type' => 'markup',
462      '#value' => t('There are no states defined for this workflow.')
463    );
464    return $form;
465  }
466  foreach ($states as $state_id => $name) {
467    foreach ($states as $nested_state_id => $nested_name) {
468      if ($nested_name == t('(creation)')) {
469        // Don't allow transition TO (creation).
470        continue;
471      }
472      if ($nested_state_id != $state_id) {
473        // Need to generate checkboxes for transition from $state to $nested_state.
474        $from = $state_id;
475        $to = $nested_state_id;
476        foreach ($roles as $rid => $role_name) {
477          $tid = workflow_get_transition_id($from, $to);
478          $form[$from][$to][$rid] = array(
479            '#type' => 'checkbox',
480            '#title' => check_plain($role_name),
481            '#default_value' => $tid ? workflow_transition_allowed($tid, $rid) : FALSE);
482        }
483      }
484    }
485  }
486  return $form;
487}
488
489/**
490 * Menu callback. Create the main workflow page, which gives an overview
491 * of workflows and workflow states.
492 */
493function workflow_overview() {
494  $workflows = workflow_get_all();
495  $row = array();
496
497  foreach ($workflows as $wid => $name) {
498    $links = array(
499      'workflow_overview_add_state' => array(
500        'title' => t('Add state'),
501        'href' => "admin/build/workflow/state/$wid"),
502      'workflow_overview_actions' => array(
503        'title' => t('Actions'),
504        'href' => "admin/build/trigger/workflow/$wid"),
505      'workflow_overview_edit' => array(
506        'title' => t('Edit'),
507        'href' => "admin/build/workflow/edit/$wid"),
508      'workflow_overview_delete' => array(
509        'title' => t('Delete'),
510        'href' => "admin/build/workflow/delete/$wid"),
511    );
512
513    // Allow modules to insert their own workflow operations.
514    $links = array_merge($links, module_invoke_all('workflow_operations', 'workflow', $wid));
515
516    $states = workflow_get_states($wid);
517    if (!module_exists('trigger') || count($states) < 2) {
518      unset($links['workflow_overview_actions']);
519    }
520
521    $row[] = array(check_plain(t($name)), theme('links', $links));
522    $subrows = array();
523
524    foreach ($states as $sid => $state_name) {
525      $state_links = array();
526      if (!workflow_is_system_state(check_plain(t($state_name)))) {
527        $state_links = array(
528          'workflow_overview_edit_state' => array(
529            'title' => t('Edit'),
530            'href' => "admin/build/workflow/state/$wid/$sid",
531          ),
532          'workflow_overview_delete_state' => array(
533            'title' => t('Delete'),
534            'href' => "admin/build/workflow/state/delete/$wid/$sid"
535          ),
536        );
537      }
538      // Allow modules to insert state operations.
539      $state_links = array_merge($state_links, module_invoke_all('workflow_operations', 'state', $wid, $sid));
540      $subrows[] = array(check_plain(t($state_name)), theme('links', $state_links));
541      unset($state_links);
542    }
543
544    $subheader_state      = array('data' => t('State'), 'style' => 'width: 30%');
545    $subheader_operations = array('data' => t('Operations'), 'style' => 'width: 70%');
546    $subheader_style      = array('style' => 'width: 100%; margin: 3px 20px 20px;');
547    $subtable = theme('table', array($subheader_state, $subheader_operations), $subrows, $subheader_style);
548
549    $row[] = array(array('data' => $subtable, 'colspan' => '2'));
550  }
551
552  if ($row) {
553    $output = theme('table', array(t('Workflow'), t('Operations')), $row);
554    $output .= drupal_get_form('workflow_types_form');
555  }
556  else {
557    $output = '<p>' . t('No workflows have been added. Would you like to <a href="@link">add a workflow</a>?', array('@link' => url('admin/build/workflow/add'))) . '</p>';
558  }
559
560  return $output;
561}
562
563/**
564 * Form builder. Create form for confirmation of deleting a workflow state.
565 *
566 * @param $wid
567 *   integer The ID of the workflow.
568 * @param $sid
569 *   The ID of the workflow state.
570 * @return
571 *   HTML form.
572 */
573function workflow_state_delete_form($form_state, $wid, $sid) {
574  $states = workflow_get_states($wid);
575  $state_name = $states[$sid];
576
577  // Will any nodes have no state if this state is deleted?
578  if ($count = db_result(db_query("SELECT COUNT(nid) FROM {workflow_node} WHERE sid = %d", $sid))) {
579    // Cannot assign a node to (creation) because that implies
580    // that the node does not exist.
581    $key = array_search(t('(creation)'), $states);
582    unset($states[$key]);
583
584    // Don't include the state to be deleted in our list of possible
585    // states that can be assigned.
586    unset($states[$sid]);
587    if ($states) {
588      $form['new_sid'] = array(
589        '#type' => 'select',
590        '#title' => t('State to be assigned to orphaned nodes'),
591        '#description' => format_plural($count, 'Since you are deleting a workflow state, a node which is in that state will be orphaned, and must be reassigned to a new state. Please choose the new state.', 'Since you are deleting a workflow state, @count nodes which are in that state will be orphaned, and must be reassigned to a new state. Please choose the new state.'),
592        '#options' => $states,
593      );
594    }
595    else {
596      $form['warning'] = array(
597        '#value' => format_plural($count, 'Since you are deleting the last workflow state in this workflow, the one remaining node which is in that state will have its workflow state removed. ', 'Since you are deleting the last workflow state in this workflow, @count nodes which are in that state will have their workflow state removed. '),
598      );
599    }
600  }
601
602  $form['wid'] = array(
603    '#type' => 'value',
604    '#value' => $wid
605  );
606  $form['sid'] = array(
607    '#type' => 'value',
608    '#value' => $sid
609  );
610
611  return confirm_form(
612    $form,
613    t('Are you sure you want to delete %title (and all its transitions)?', array('%title' => $state_name)),
614    !empty($_GET['destination']) ? $_GET['destination'] : 'admin/build/workflow',
615    t('This action cannot be undone.'),
616    t('Delete'),
617    t('Cancel')
618  );
619}
620
621/**
622 * Submit handler for workflow state deletion form.
623 *
624 * @see workflow_state_delete_form()
625 */
626function workflow_state_delete_form_submit($form, &$form_state) {
627  $states = workflow_get_states($form_state['values']['wid']);
628  $state_name = $states[$form_state['values']['sid']];
629  if ($form_state['values']['confirm'] == 1) {
630    $new_sid = isset($form_state['values']['new_sid']) ? $form_state['values']['new_sid'] : NULL;
631    workflow_state_delete($form_state['values']['sid'], $new_sid);
632    watchdog('workflow', 'Deleted workflow state %name', array('%name' => $state_name));
633    drupal_set_message(t('The workflow state %name was deleted.', array('%name' => $state_name)));
634  }
635  $form_state['redirect'] = 'admin/build/workflow';
636}
637
638/**
639 * Form builder. Allow administrator to map workflows to content types
640 * and determine placement.
641 */
642function workflow_types_form() {
643  $form = array();
644  $workflows = array('<' . t('None') . '>') + workflow_get_all();
645  if (count($workflows) == 0) {
646    return $form;
647  }
648
649  $type_map = array();
650  $result = db_query("SELECT wid, type FROM {workflow_type_map}");
651  while ($data = db_fetch_object($result)) {
652    $type_map[$data->type] = $data->wid;
653  }
654
655  $form['#theme'] = 'workflow_types_form';
656  $form['#tree'] = TRUE;
657  $form['help'] = array(
658    '#type' => 'item',
659    '#value' => t('Each content type may have a separate workflow. The form for changing workflow state can be displayed when editing a node, editing a comment for a node, or both.'),
660  );
661
662  foreach (node_get_types('names') as $type => $name) {
663    $form[$type]['workflow'] = array(
664      '#type' => 'select',
665      '#title' => check_plain($name),
666      '#options' => $workflows,
667      '#default_value' => isset($type_map[$type]) ? $type_map[$type] : 0
668    );
669    $form[$type]['placement'] = array(
670      '#type' => 'checkboxes',
671      '#options' => array(
672        'node' => t('Post'),
673        'comment' => t('Comment'),
674      ),
675      '#default_value' => variable_get('workflow_' . $type, array('node')),
676    );
677  }
678  $form['submit'] = array(
679    '#type' => 'submit',
680    '#value' => t('Save workflow mapping')
681  );
682  return $form;
683}
684
685/**
686 * Theme the workflow type mapping form.
687 */
688function theme_workflow_types_form($form) {
689  $header = array(t('Content Type'), t('Workflow'), t('Display Workflow Form for:'));
690  $rows = array();
691  foreach (node_get_types('names') as $type => $name) {
692    $name = $form[$type]['workflow']['#title'];
693    unset($form[$type]['workflow']['#title']);
694    $rows[] = array($name, drupal_render($form[$type]['workflow']), drupal_render($form[$type]['placement']));
695  }
696  $output = drupal_render($form['help']);
697  $output .= theme('table', $header, $rows);
698  return $output . drupal_render($form);
699}
700
701/**
702 * Submit handler for workflow type mapping form.
703 *
704 * @see workflow_types_form()
705 */
706function workflow_types_form_submit($form, &$form_state) {
707  workflow_types_save($form_state['values']);
708  drupal_set_message(t('The workflow mapping was saved.'));
709  menu_rebuild();
710  $form_state['redirect'] = 'admin/build/workflow';
711}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.