views_handler_field_url.inc

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

File

handlers/views_handler_field_url.inc
View source
  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_url extends views_handler_field {
  8. function option_definition() {
  9. $options = parent::option_definition();
  10. $options['display_as_link'] = array('default' => TRUE);
  11. return $options;
  12. }
  13. /**
  14. * Provide link to the page being visited.
  15. */
  16. function options_form(&$form, &$form_state) {
  17. parent::options_form($form, $form_state);
  18. $form['display_as_link'] = array(
  19. '#title' => t('Display as link'),
  20. '#type' => 'checkbox',
  21. '#default_value' => !empty($this->options['display_as_link']),
  22. );
  23. }
  24. function render($values) {
  25. $value = $values->{$this->field_alias};
  26. if (!empty($this->options['display_as_link'])) {
  27. return l(check_plain($value), $value, array('html' => TRUE));
  28. }
  29. else {
  30. return check_url($value);
  31. }
  32. }
  33. }