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