webform_handler_field_node_link_results.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Views handler to display a results link for Webform submissions.
  4. *
  5. * Field handler to present a link node edit.
  6. */
  7. class webform_handler_field_node_link_results extends views_handler_field_node_link {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function option_definition() {
  12. $options = parent::option_definition();
  13. $options['subpath'] = array('default' => '');
  14. return $options;
  15. }
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. $form['subpath'] = array(
  22. '#type' => 'textfield',
  23. '#title' => t('Subpath'),
  24. '#default_value' => $this->options['subpath'],
  25. '#field_prefix' => 'node/NID/webform-results/',
  26. );
  27. }
  28. /**
  29. * Renders the link.
  30. */
  31. public function render_link($node, $values) {
  32. // Ensure node is webform-enabled and the user has access node's webform
  33. // results.
  34. if (!in_array($node->type, webform_node_types()) || !webform_results_access($node)) {
  35. return;
  36. }
  37. // For clear, ensure user has access to clear all the submissions.
  38. if (stripos($this->options['subpath'], 'clear') === 0 && !user_access('delete all webform submissions')) {
  39. return;
  40. }
  41. $this->options['alter']['make_link'] = TRUE;
  42. $this->options['alter']['path'] = "node/$node->nid/webform-results" .
  43. (strlen($this->options['subpath']) ? '/' . $this->options['subpath'] : '');
  44. $text = !empty($this->options['text']) ? $this->options['text'] : t('results');
  45. return $text;
  46. }
  47. }