views_handler_field_url.inc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_url.
  5. */
  6. /**
  7. * Field handler 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. /**
  13. * {@inheritdoc}
  14. */
  15. public function option_definition() {
  16. $options = parent::option_definition();
  17. $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
  18. return $options;
  19. }
  20. /**
  21. * Provide link to the page being visited.
  22. */
  23. public function options_form(&$form, &$form_state) {
  24. $form['display_as_link'] = array(
  25. '#title' => t('Display as link'),
  26. '#type' => 'checkbox',
  27. '#default_value' => !empty($this->options['display_as_link']),
  28. );
  29. parent::options_form($form, $form_state);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public 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. }