views_handler_field_aggregator_category.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_aggregator_category.
  5. */
  6. /**
  7. * Field handler to provide simple renderer that allows linking to aggregator
  8. * category.
  9. *
  10. * @ingroup views_field_handlers
  11. */
  12. class views_handler_field_aggregator_category extends views_handler_field {
  13. /**
  14. * Constructor to provide additional field to add.
  15. */
  16. public function construct() {
  17. parent::construct();
  18. $this->additional_fields['cid'] = 'cid';
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function option_definition() {
  24. $options = parent::option_definition();
  25. $options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE);
  26. return $options;
  27. }
  28. /**
  29. * Provide link to category option
  30. */
  31. public function options_form(&$form, &$form_state) {
  32. $form['link_to_category'] = array(
  33. '#title' => t('Link this field to its aggregator category page'),
  34. '#description' => t('This will override any other link you have set.'),
  35. '#type' => 'checkbox',
  36. '#default_value' => !empty($this->options['link_to_category']),
  37. );
  38. parent::options_form($form, $form_state);
  39. }
  40. /**
  41. * Render whatever the data is as a link to the category.
  42. *
  43. * Data should be made XSS safe prior to calling this function.
  44. */
  45. public function render_link($data, $values) {
  46. $cid = $this->get_value($values, 'cid');
  47. if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') {
  48. $this->options['alter']['make_link'] = TRUE;
  49. $this->options['alter']['path'] = "aggregator/category/$cid";
  50. }
  51. return $data;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function render($values) {
  57. $value = $this->get_value($values);
  58. return $this->render_link($this->sanitize_value($value), $values);
  59. }
  60. }