workflow_views_handler_field_sid.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Provide views field handler for workflow.module.
  5. */
  6. /**
  7. * Field handler to provide simple status name or renderer.
  8. */
  9. class workflow_views_handler_field_sid extends views_handler_field {
  10. function option_definition() {
  11. $options = parent::option_definition();
  12. $options['value'] = array('default' => FALSE, 'bool' => TRUE);
  13. return $options;
  14. }
  15. function options_form(&$form, &$form_state) {
  16. $form['value'] = array(
  17. '#title' => t('Display value'),
  18. '#description' => t('If checked, row field value will be displayed.'),
  19. '#type' => 'checkbox',
  20. '#default_value' => $this->options['value'],
  21. );
  22. parent::options_form($form, $form_state);
  23. }
  24. function render($values) {
  25. if ($this->options['value']) {
  26. if (empty($values->{$this->field_alias})) {
  27. return NULL;
  28. }
  29. return $values->{$this->field_alias};
  30. }
  31. else {
  32. if (empty($values->{$this->field_alias})) {
  33. return t('No state');
  34. }
  35. static $states;
  36. if (!isset($states)) {
  37. $states = array();
  38. foreach (workflow_get_workflow_states() as $state) {
  39. $states[$state->sid] = $state->state;
  40. }
  41. }
  42. $output = t($states[$values->{$this->field_alias}]);
  43. if (empty($output)) {
  44. $output = t('Unknown state');
  45. }
  46. return check_plain($output);
  47. }
  48. }
  49. }