5 * Contains the node view row style plugin.
9 * Plugin which performs a node_view on the resulting object.
11 * Most of the code on this object is in the theme function.
13 * @ingroup views_row_plugins
15 class views_plugin_row_node_view extends views_plugin_row {
16 // Basic properties that let the row style follow relationships.
17 var $base_table = 'node';
18 var $base_field = 'nid';
20 // Stores the nodes loaded with pre_render.
23 function init(&$view, &$display, $options = NULL) {
24 parent::init($view, $display, $options);
25 // Handle existing views with the deprecated 'teaser' option.
26 if (isset($this->options['teaser'])) {
27 $this->options['build_mode'] = $this->options['teaser'] ? 'teaser' : 'full';
29 // Handle existing views which has used build_mode instead of view_mode.
30 if (isset($this->options['build_mode'])) {
31 $this->options['view_mode'] = $this->options['build_mode'];
35 function option_definition() {
36 $options = parent::option_definition();
38 $options['view_mode'] = array('default' => 'teaser');
39 $options['links'] = array('default' => TRUE, 'bool' => TRUE);
40 $options['comments'] = array('default' => FALSE, 'bool' => TRUE);
45 function options_form(&$form, &$form_state) {
46 parent::options_form($form, $form_state);
48 $options = $this->options_form_summary_options();
49 $form['view_mode'] = array(
51 '#options' => $options,
52 '#title' => t('View mode'),
53 '#default_value' => $this->options['view_mode'],
55 $form['links'] = array(
56 '#type' => 'checkbox',
57 '#title' => t('Display links'),
58 '#default_value' => $this->options['links'],
60 $form['comments'] = array(
61 '#type' => 'checkbox',
62 '#title' => t('Display comments'),
63 '#default_value' => $this->options['comments'],
68 * Return the main options, which are shown in the summary title.
70 function options_form_summary_options() {
71 $entity_info = entity_get_info('node');
73 if (!empty($entity_info['view modes'])) {
74 foreach ($entity_info['view modes'] as $mode => $settings) {
75 $options[$mode] = $settings['label'];
78 if (empty($options)) {
80 'teaser' => t('Teaser'),
81 'full' => t('Full content')
88 function summary_title() {
89 $options = $this->options_form_summary_options();
90 return check_plain($options[$this->options['view_mode']]);
93 function pre_render($values) {
95 foreach ($values as $row) {
96 $nids[] = $row->{$this->field_alias};
98 $this->nodes = node_load_multiple($nids);
101 function render($row) {
102 if (isset($this->nodes[$row->{$this->field_alias}])) {
103 $node = $this->nodes[$row->{$this->field_alias}];
104 $node->view = $this->view;
105 $build = node_view($node, $this->options['view_mode']);
107 return drupal_render($build);