views_handler_field_aggregator_title_link.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_aggregator_title_link.
  5. */
  6. /**
  7. * Field handler that turns an item's title into a clickable link to the
  8. * original source article.
  9. *
  10. * @ingroup views_field_handlers
  11. */
  12. class views_handler_field_aggregator_title_link extends views_handler_field {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function construct() {
  17. parent::construct();
  18. $this->additional_fields['link'] = 'link';
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function option_definition() {
  24. $options = parent::option_definition();
  25. $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
  26. return $options;
  27. }
  28. /**
  29. * Provide link to the page being visited.
  30. */
  31. public function options_form(&$form, &$form_state) {
  32. $form['display_as_link'] = array(
  33. '#title' => t('Display as link'),
  34. '#type' => 'checkbox',
  35. '#default_value' => !empty($this->options['display_as_link']),
  36. );
  37. parent::options_form($form, $form_state);
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function render($values) {
  43. $value = $this->get_value($values);
  44. return $this->render_link($this->sanitize_value($value), $values);
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function render_link($data, $values) {
  50. $link = $this->get_value($values, 'link');
  51. if (!empty($this->options['display_as_link'])) {
  52. $this->options['alter']['make_link'] = TRUE;
  53. $this->options['alter']['path'] = $link;
  54. $this->options['alter']['html'] = TRUE;
  55. }
  56. return $data;
  57. }
  58. }