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

File

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