views_handler_field_aggregator_category.inc

  1. 3.x modules/aggregator/views_handler_field_aggregator_category.inc
  2. 2.x modules/aggregator/views_handler_field_aggregator_category.inc

Definition of views_handler_field_aggregator_category.

File

modules/aggregator/views_handler_field_aggregator_category.inc
View source
  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. function construct() {
  17. parent::construct();
  18. $this->additional_fields['cid'] = 'cid';
  19. }
  20. function option_definition() {
  21. $options = parent::option_definition();
  22. $options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE);
  23. return $options;
  24. }
  25. /**
  26. * Provide link to category option
  27. */
  28. function options_form(&$form, &$form_state) {
  29. $form['link_to_category'] = array(
  30. '#title' => t('Link this field to its aggregator category page'),
  31. '#description' => t('This will override any other link you have set.'),
  32. '#type' => 'checkbox',
  33. '#default_value' => !empty($this->options['link_to_category']),
  34. );
  35. parent::options_form($form, $form_state);
  36. }
  37. /**
  38. * Render whatever the data is as a link to the category.
  39. *
  40. * Data should be made XSS safe prior to calling this function.
  41. */
  42. function render_link($data, $values) {
  43. $cid = $this->get_value($values, 'cid');
  44. if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') {
  45. $this->options['alter']['make_link'] = TRUE;
  46. $this->options['alter']['path'] = "aggregator/category/$cid";
  47. }
  48. return $data;
  49. }
  50. function render($values) {
  51. $value = $this->get_value($values);
  52. return $this->render_link($this->sanitize_value($value), $values);
  53. }
  54. }