views_handler_field_node_revision.inc

  1. 3.x modules/node/views_handler_field_node_revision.inc
  2. 2.x modules/node/views_handler_field_node_revision.inc

Contains the basic 'node_revision' field handler.

File

modules/node/views_handler_field_node_revision.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the basic 'node_revision' field handler.
  5. */
  6. class views_handler_field_node_revision extends views_handler_field_node {
  7. function init(&$view, $options) {
  8. parent::init($view, $options);
  9. if (!empty($this->options['link_to_node_revision'])) {
  10. $this->additional_fields['vid'] = 'vid';
  11. $this->additional_fields['nid'] = 'nid';
  12. if (module_exists('translation')) {
  13. $this->additional_fields['language'] = array('table' => 'node', 'field' => 'language');
  14. }
  15. }
  16. }
  17. function option_definition() {
  18. $options = parent::option_definition();
  19. $options['link_to_node_revision'] = array('default' => FALSE);
  20. return $options;
  21. }
  22. /**
  23. * Provide link to revision option.
  24. */
  25. function options_form(&$form, &$form_state) {
  26. parent::options_form($form, $form_state);
  27. $form['link_to_node_revision'] = array(
  28. '#title' => t('Link this field to its node revision'),
  29. '#description' => t('This will override any other link you have set.'),
  30. '#type' => 'checkbox',
  31. '#default_value' => !empty($this->options['link_to_node_revision']),
  32. );
  33. }
  34. /**
  35. * Render whatever the data is as a link to the node.
  36. *
  37. * Data should be made XSS safe prior to calling this function.
  38. */
  39. function render_link($data, $values) {
  40. if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') {
  41. $this->options['alter']['make_link'] = TRUE;
  42. $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']} . '/revisions/' . $values->{$this->aliases['vid']} .'/view';
  43. if (isset($this->aliases['language'])) {
  44. $languages = language_list();
  45. if (isset($languages[$values->{$this->aliases['language']}])) {
  46. $this->options['alter']['language'] = $languages[$values->{$this->aliases['language']}];
  47. }
  48. }
  49. }
  50. else {
  51. return parent::render_link($data, $values);
  52. }
  53. return $data;
  54. }
  55. }