workflow_views_handler_field_comment_link_edit.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * Field handler to present a link to edit a workflow log comment.
  5. */
  6. class workflow_views_handler_field_comment_link_edit extends views_handler_field {
  7. function construct() {
  8. parent::construct();
  9. $this->additional_fields['hid'] = 'hid';
  10. }
  11. function option_definition() {
  12. $options = parent::option_definition();
  13. $options['text'] = array(
  14. 'default' => '',
  15. 'translatable' => TRUE,
  16. );
  17. return $options;
  18. }
  19. function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. $form['text'] = array(
  22. '#type' => 'textfield',
  23. '#title' => t('Text to display'),
  24. '#default_value' => $this->options['text'],
  25. );
  26. }
  27. function query() {
  28. $this->ensure_my_table();
  29. $this->add_additional_fields();
  30. }
  31. function render($values) {
  32. if (!user_access('edit workflow comment')) {
  33. return;
  34. }
  35. if (!$hid = $values->{$this->aliases['hid']}) {
  36. // No link if entity has no history.
  37. return;
  38. }
  39. $text = empty($this->options['text']) ? t('edit comment') : $this->options['text'];
  40. return l($text, "workflow_transition/$hid/edit", array('query' => drupal_get_destination()));
  41. }
  42. }