Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / handlers / views_handler_field_url.inc @ 4003efde

1
<?php
2

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

    
8
/**
9
 * Field handler 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

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function option_definition() {
19
    $options = parent::option_definition();
20

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

    
23
    return $options;
24
  }
25

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

    
38
  /**
39
   * {@inheritdoc}
40
   */
41
  public function render($values) {
42
    $value = $this->get_value($values);
43
    if (!empty($this->options['display_as_link'])) {
44
      $this->options['alter']['make_link'] = TRUE;
45
      $this->options['alter']['path'] = $value;
46
      $text = !empty($this->options['text']) ? $this->sanitize_value($this->options['text']) : $this->sanitize_value($value, 'url');
47
      return $text;
48
    }
49
    else {
50
      return $this->sanitize_value($value, 'url');
51
    }
52
  }
53

    
54
}