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

Definition of views_handler_field_node_revision.

File

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