views_handler_field_comment_link_edit.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_comment_link_edit.
  5. */
  6. /**
  7. * Field handler to present a link node edit.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_comment_link_edit extends views_handler_field_comment_link {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function option_definition() {
  16. $options = parent::option_definition();
  17. $options['destination'] = array('default' => FALSE, 'bool' => TRUE);
  18. return $options;
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function options_form(&$form, &$form_state) {
  24. parent::options_form($form, $form_state);
  25. $form['destination'] = array(
  26. '#type' => 'checkbox',
  27. '#title' => t('Use destination'),
  28. '#description' => t('Add destination to the link'),
  29. '#default_value' => $this->options['destination'],
  30. '#fieldset' => 'more',
  31. );
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function render_link($data, $values) {
  37. parent::render_link($data, $values);
  38. // Ensure user has access to edit this comment.
  39. $comment = $this->get_value($values);
  40. if (!comment_access('edit', $comment)) {
  41. return;
  42. }
  43. $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
  44. unset($this->options['alter']['fragment']);
  45. if (!empty($this->options['destination'])) {
  46. $this->options['alter']['query'] = drupal_get_destination();
  47. }
  48. $this->options['alter']['path'] = "comment/" . $comment->cid . "/edit";
  49. return $text;
  50. }
  51. }