1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_row_node_view.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Plugin which performs a node_view on the resulting object.
|
10
|
*
|
11
|
* Most of the code on this object is in the theme function.
|
12
|
*
|
13
|
* @ingroup views_row_plugins
|
14
|
*/
|
15
|
class views_plugin_row_node_view extends views_plugin_row {
|
16
|
|
17
|
/**
|
18
|
* Basic properties that let the row style follow relationships.
|
19
|
*/
|
20
|
public $base_table = 'node';
|
21
|
|
22
|
/**
|
23
|
*
|
24
|
*/
|
25
|
public $base_field = 'nid';
|
26
|
|
27
|
/**
|
28
|
* Stores the nodes loaded with pre_render.
|
29
|
*/
|
30
|
public $nodes = array();
|
31
|
|
32
|
/**
|
33
|
* {@inheritdoc}
|
34
|
*/
|
35
|
public function init(&$view, &$display, $options = NULL) {
|
36
|
parent::init($view, $display, $options);
|
37
|
// Handle existing views with the deprecated 'teaser' option.
|
38
|
if (isset($this->options['teaser'])) {
|
39
|
$this->options['build_mode'] = $this->options['teaser'] ? 'teaser' : 'full';
|
40
|
}
|
41
|
// Handle existing views which has used build_mode instead of view_mode.
|
42
|
if (isset($this->options['build_mode'])) {
|
43
|
$this->options['view_mode'] = $this->options['build_mode'];
|
44
|
}
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* {@inheritdoc}
|
49
|
*/
|
50
|
public function option_definition() {
|
51
|
$options = parent::option_definition();
|
52
|
|
53
|
$options['view_mode'] = array('default' => 'teaser');
|
54
|
$options['links'] = array('default' => TRUE, 'bool' => TRUE);
|
55
|
$options['comments'] = array('default' => FALSE, 'bool' => TRUE);
|
56
|
|
57
|
return $options;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* {@inheritdoc}
|
62
|
*/
|
63
|
public function options_form(&$form, &$form_state) {
|
64
|
parent::options_form($form, $form_state);
|
65
|
|
66
|
$options = $this->options_form_summary_options();
|
67
|
$form['view_mode'] = array(
|
68
|
'#type' => 'select',
|
69
|
'#options' => $options,
|
70
|
'#title' => t('View mode'),
|
71
|
'#default_value' => $this->options['view_mode'],
|
72
|
);
|
73
|
$form['links'] = array(
|
74
|
'#type' => 'checkbox',
|
75
|
'#title' => t('Display links'),
|
76
|
'#default_value' => $this->options['links'],
|
77
|
);
|
78
|
$form['comments'] = array(
|
79
|
'#type' => 'checkbox',
|
80
|
'#title' => t('Display comments'),
|
81
|
'#default_value' => $this->options['comments'],
|
82
|
'#access' => module_exists('comment'),
|
83
|
);
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Return the main options, which are shown in the summary title.
|
88
|
*/
|
89
|
public function options_form_summary_options() {
|
90
|
$entity_info = entity_get_info('node');
|
91
|
$options = array();
|
92
|
if (!empty($entity_info['view modes'])) {
|
93
|
foreach ($entity_info['view modes'] as $mode => $settings) {
|
94
|
$options[$mode] = $settings['label'];
|
95
|
}
|
96
|
}
|
97
|
if (empty($options)) {
|
98
|
$options = array(
|
99
|
'teaser' => t('Teaser'),
|
100
|
'full' => t('Full content'),
|
101
|
);
|
102
|
}
|
103
|
|
104
|
return $options;
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* {@inheritdoc}
|
109
|
*/
|
110
|
public function summary_title() {
|
111
|
$options = $this->options_form_summary_options();
|
112
|
return check_plain($options[$this->options['view_mode']]);
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* {@inheritdoc}
|
117
|
*/
|
118
|
public function pre_render($values) {
|
119
|
$nids = array();
|
120
|
foreach ($values as $row) {
|
121
|
$nids[] = $row->{$this->field_alias};
|
122
|
}
|
123
|
$this->nodes = node_load_multiple($nids);
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* {@inheritdoc}
|
128
|
*/
|
129
|
public function render($row) {
|
130
|
if (isset($this->nodes[$row->{$this->field_alias}])) {
|
131
|
$node = $this->nodes[$row->{$this->field_alias}];
|
132
|
$node->view = $this->view;
|
133
|
$build = node_view($node, $this->options['view_mode']);
|
134
|
|
135
|
return drupal_render($build);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
}
|