redirect_handler_field_redirect_redirect.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @file
  4. * Redirect field handler for {redirect}.redirect.
  5. */
  6. class redirect_handler_field_redirect_redirect extends views_handler_field {
  7. function construct() {
  8. parent::construct();
  9. $this->additional_fields['redirect'] = 'redirect';
  10. $this->additional_fields['redirect_options'] = 'redirect_options';
  11. }
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['text'] = array('default' => '', 'translatable' => TRUE);
  15. $options['absolute'] = array('default' => FALSE);
  16. $options['alter']['contains']['make_link']['default'] = TRUE;
  17. return $options;
  18. }
  19. function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. // This field will never be empty
  22. $form['empty']['#access'] = FALSE;
  23. $form['empty_zero']['#access'] = FALSE;
  24. $form['hide_empty']['#access'] = FALSE;
  25. $form['alter']['make_link']['#description'] = t('If checked, this field will be made into a link.');
  26. $form['alter']['absolute']['#access'] = FALSE;
  27. $form['alter']['path']['#access'] = FALSE;
  28. $form['text'] = array(
  29. '#type' => 'textfield',
  30. '#title' => t('Text to display'),
  31. '#default_value' => $this->options['text'],
  32. );
  33. $form['absolute'] = array(
  34. '#type' => 'checkbox',
  35. '#title' => t('Use absolute link (begins with "http://")'),
  36. '#default_value' => $this->options['absolute'],
  37. '#description' => t('If you want to use this as in "output this field as link" in "link path", you have to enabled this option.'),
  38. );
  39. }
  40. function render($values) {
  41. $redirect = $values->{$this->aliases['redirect']};
  42. $redirect_options = unserialize($values->{$this->aliases['redirect_options']});
  43. $redirect_options['absolute'] = !empty($this->options['absolute']);
  44. $url = redirect_url($redirect, $redirect_options);
  45. $text = !empty($this->options['text']) ? $this->options['text'] : $url;
  46. if (!empty($this->options['alter']['make_link'])) {
  47. $this->options['alter']['path'] = $url;
  48. $this->options['alter']['absolute'] = $redirect_options['absolute'];
  49. }
  50. else {
  51. $text = check_plain($text);
  52. }
  53. return $text;
  54. }
  55. }