views_handler_field_comment_link_approve.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_comment_link_approve.
  5. */
  6. /**
  7. * Provides a comment approve link.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_comment_link_approve extends views_handler_field_comment_link {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function access() {
  16. //needs permission to administer comments in general
  17. return user_access('administer comments');
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function render_link($data, $values) {
  23. $status = $this->get_value($values, 'status');
  24. // Don't show an approve link on published nodes.
  25. if ($status == COMMENT_PUBLISHED) {
  26. return;
  27. }
  28. $text = !empty($this->options['text']) ? $this->options['text'] : t('approve');
  29. $cid = $this->get_value($values, 'cid');
  30. $this->options['alter']['make_link'] = TRUE;
  31. $this->options['alter']['path'] = "comment/" . $cid . "/approve";
  32. $this->options['alter']['query'] = drupal_get_destination() + array('token' => drupal_get_token("comment/$cid/approve"));
  33. return $text;
  34. }
  35. }