workflow_views_handler_field_sid.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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('Determines how the state will be displayed.'),
  19. '#type' => 'select',
  20. '#options' => array(
  21. '0' => t('State name'),
  22. '1' => t('State value'), // Keep this value for backwards compatibility.
  23. 'count' => t('Count number of entities with this state'),
  24. ),
  25. '#default_value' => $this->options['value'],
  26. );
  27. parent::options_form($form, $form_state);
  28. }
  29. function render($values) {
  30. $sid = $values->{$this->field_alias};
  31. if ($this->options['value'] == '1') {
  32. return (empty($sid)) ? NULL : $sid;
  33. }
  34. elseif ($this->options['value'] == 'count') {
  35. $state = workflow_state_load_single($sid);
  36. return (empty($sid)) ? 0 : $state->count();
  37. }
  38. else {
  39. return workflow_get_sid_label($sid);
  40. }
  41. }
  42. }