1 | <?php |
---|
2 | /** |
---|
3 | * Field handler to provide simple renderer that turns a URL into a clickable link. |
---|
4 | * |
---|
5 | * @ingroup views_field_handlers |
---|
6 | */ |
---|
7 | class views_handler_field_accesslog_path extends views_handler_field { |
---|
8 | /** |
---|
9 | * Override init function to provide generic option to link to node. |
---|
10 | */ |
---|
11 | function init(&$view, &$options) { |
---|
12 | parent::init($view, $options); |
---|
13 | if (!empty($this->options['display_as_link'])) { |
---|
14 | $this->additional_fields['path'] = 'path'; |
---|
15 | } |
---|
16 | } |
---|
17 | |
---|
18 | function option_definition() { |
---|
19 | $options = parent::option_definition(); |
---|
20 | |
---|
21 | $options['display_as_link'] = array('default' => TRUE); |
---|
22 | |
---|
23 | return $options; |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * Provide link to the page being visited. |
---|
28 | */ |
---|
29 | function options_form(&$form, &$form_state) { |
---|
30 | parent::options_form($form, $form_state); |
---|
31 | $form['display_as_link'] = array( |
---|
32 | '#title' => t('Display as link'), |
---|
33 | '#type' => 'checkbox', |
---|
34 | '#default_value' => !empty($this->options['display_as_link']), |
---|
35 | ); |
---|
36 | } |
---|
37 | |
---|
38 | function render($values) { |
---|
39 | $value = $this->get_value($values); |
---|
40 | return $this->render_link($this->sanitize_value($value), $values); |
---|
41 | } |
---|
42 | |
---|
43 | function render_link($data, $values) { |
---|
44 | if (!empty($this->options['display_as_link'])) { |
---|
45 | $this->options['alter']['make_link'] = TRUE; |
---|
46 | $this->options['alter']['path'] = $this->get_value($values, 'path'); |
---|
47 | $this->options['alter']['html'] = TRUE; |
---|
48 | } |
---|
49 | |
---|
50 | return $data; |
---|
51 | } |
---|
52 | } |
---|