Projet

Général

Profil

Paste
Télécharger (1,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / handlers / views_handler_field_url.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_url.
6
 */
7

    
8
/**
9
 * Field handler to provide simple renderer that turns a URL into a clickable link.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_url extends views_handler_field {
14
  function option_definition() {
15
    $options = parent::option_definition();
16

    
17
    $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
18

    
19
    return $options;
20
  }
21

    
22
  /**
23
   * Provide link to the page being visited.
24
   */
25
  function options_form(&$form, &$form_state) {
26
    $form['display_as_link'] = array(
27
      '#title' => t('Display as link'),
28
      '#type' => 'checkbox',
29
      '#default_value' => !empty($this->options['display_as_link']),
30
    );
31
    parent::options_form($form, $form_state);
32
  }
33

    
34
  function render($values) {
35
    $value = $this->get_value($values);
36
    if (!empty($this->options['display_as_link'])) {
37
      $this->options['alter']['make_link'] = TRUE;
38
      $this->options['alter']['path'] = $value;
39
      $text = !empty($this->options['text']) ? $this->sanitize_value($this->options['text']) : $this->sanitize_value($value, 'url');
40
      return $text;
41
    }
42
    else {
43
      return $this->sanitize_value($value, 'url');
44
    }
45
  }
46
}