views_handler_field_url.inc

  1. 3.x handlers/views_handler_field_url.inc
  2. 2.x handlers/views_handler_field_url.inc

Definition of views_handler_field_url.

File

handlers/views_handler_field_url.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_url.
  5. */
  6. /**
  7. * Field handler to provide simple renderer that turns a URL into a clickable link.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_url extends views_handler_field {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
  15. return $options;
  16. }
  17. /**
  18. * Provide link to the page being visited.
  19. */
  20. function options_form(&$form, &$form_state) {
  21. $form['display_as_link'] = array(
  22. '#title' => t('Display as link'),
  23. '#type' => 'checkbox',
  24. '#default_value' => !empty($this->options['display_as_link']),
  25. );
  26. parent::options_form($form, $form_state);
  27. }
  28. function render($values) {
  29. $value = $this->get_value($values);
  30. if (!empty($this->options['display_as_link'])) {
  31. $this->options['alter']['make_link'] = TRUE;
  32. $this->options['alter']['path'] = $value;
  33. $text = !empty($this->options['text']) ? $this->sanitize_value($this->options['text']) : $this->sanitize_value($value, 'url');
  34. return $text;
  35. }
  36. else {
  37. return $this->sanitize_value($value, 'url');
  38. }
  39. }
  40. }