views_plugin_row_node_view.inc

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

Contains the node view row style plugin.

File

modules/node/views_plugin_row_node_view.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the node view row style plugin.
  5. */
  6. /**
  7. * Plugin which performs a node_view on the resulting object.
  8. *
  9. * Most of the code on this object is in the theme function.
  10. *
  11. * @ingroup views_row_plugins
  12. */
  13. class views_plugin_row_node_view extends views_plugin_row {
  14. // Basic properties that let the row style follow relationships.
  15. var $base_table = 'node';
  16. var $base_field = 'nid';
  17. // Stores the nodes loaded with pre_render.
  18. var $nodes = array();
  19. function init(&$view, &$display, $options = NULL) {
  20. parent::init($view, $display, $options);
  21. // Handle existing views with the deprecated 'teaser' option.
  22. if (isset($this->options['teaser'])) {
  23. $this->options['build_mode'] = $this->options['teaser'] ? 'teaser' : 'full';
  24. }
  25. // Handle existing views which has used build_mode instead of view_mode.
  26. if (isset($this->options['build_mode'])) {
  27. $this->options['view_mode'] = $this->options['build_mode'];
  28. }
  29. }
  30. function option_definition() {
  31. $options = parent::option_definition();
  32. $options['view_mode'] = array('default' => 'teaser');
  33. $options['links'] = array('default' => TRUE, 'bool' => TRUE);
  34. $options['comments'] = array('default' => FALSE, 'bool' => TRUE);
  35. return $options;
  36. }
  37. function options_form(&$form, &$form_state) {
  38. parent::options_form($form, $form_state);
  39. $options = $this->options_form_summary_options();
  40. $form['view_mode'] = array(
  41. '#type' => 'select',
  42. '#options' => $options,
  43. '#title' => t('View mode'),
  44. '#default_value' => $this->options['view_mode'],
  45. );
  46. $form['links'] = array(
  47. '#type' => 'checkbox',
  48. '#title' => t('Display links'),
  49. '#default_value' => $this->options['links'],
  50. );
  51. $form['comments'] = array(
  52. '#type' => 'checkbox',
  53. '#title' => t('Display comments'),
  54. '#default_value' => $this->options['comments'],
  55. );
  56. }
  57. /**
  58. * Return the main options, which are shown in the summary title.
  59. */
  60. function options_form_summary_options() {
  61. $entity_info = entity_get_info('node');
  62. $options = array();
  63. if (!empty($entity_info['view modes'])) {
  64. foreach ($entity_info['view modes'] as $mode => $settings) {
  65. $options[$mode] = $settings['label'];
  66. }
  67. }
  68. if (empty($options)) {
  69. $options = array(
  70. 'teaser' => t('Teaser'),
  71. 'full' => t('Full content')
  72. );
  73. }
  74. return $options;
  75. }
  76. function summary_title() {
  77. $options = $this->options_form_summary_options();
  78. return check_plain($options[$this->options['view_mode']]);
  79. }
  80. function pre_render($values) {
  81. $nids = array();
  82. foreach ($values as $row) {
  83. $nids[] = $row->{$this->field_alias};
  84. }
  85. $this->nodes = node_load_multiple($nids);
  86. }
  87. function render($row) {
  88. if (isset($this->nodes[$row->{$this->field_alias}])) {
  89. $node = $this->nodes[$row->{$this->field_alias}];
  90. $node->view = $this->view;
  91. $build = node_view($node, $this->options['view_mode']);
  92. return drupal_render($build);
  93. }
  94. }
  95. }