commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / views / modules / node / views_plugin_row_node_view.inc
1 <?php
2
3 /**
4 * @file
5 * Contains the node view row style plugin.
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 // Basic properties that let the row style follow relationships.
17 var $base_table = 'node';
18 var $base_field = 'nid';
19
20 // Stores the nodes loaded with pre_render.
21 var $nodes = array();
22
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';
28 }
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'];
32 }
33 }
34
35 function option_definition() {
36 $options = parent::option_definition();
37
38 $options['view_mode'] = array('default' => 'teaser');
39 $options['links'] = array('default' => TRUE, 'bool' => TRUE);
40 $options['comments'] = array('default' => FALSE, 'bool' => TRUE);
41
42 return $options;
43 }
44
45 function options_form(&$form, &$form_state) {
46 parent::options_form($form, $form_state);
47
48 $options = $this->options_form_summary_options();
49 $form['view_mode'] = array(
50 '#type' => 'select',
51 '#options' => $options,
52 '#title' => t('View mode'),
53 '#default_value' => $this->options['view_mode'],
54 );
55 $form['links'] = array(
56 '#type' => 'checkbox',
57 '#title' => t('Display links'),
58 '#default_value' => $this->options['links'],
59 );
60 $form['comments'] = array(
61 '#type' => 'checkbox',
62 '#title' => t('Display comments'),
63 '#default_value' => $this->options['comments'],
64 );
65 }
66
67 /**
68 * Return the main options, which are shown in the summary title.
69 */
70 function options_form_summary_options() {
71 $entity_info = entity_get_info('node');
72 $options = array();
73 if (!empty($entity_info['view modes'])) {
74 foreach ($entity_info['view modes'] as $mode => $settings) {
75 $options[$mode] = $settings['label'];
76 }
77 }
78 if (empty($options)) {
79 $options = array(
80 'teaser' => t('Teaser'),
81 'full' => t('Full content')
82 );
83 }
84
85 return $options;
86 }
87
88 function summary_title() {
89 $options = $this->options_form_summary_options();
90 return check_plain($options[$this->options['view_mode']]);
91 }
92
93 function pre_render($values) {
94 $nids = array();
95 foreach ($values as $row) {
96 $nids[] = $row->{$this->field_alias};
97 }
98 $this->nodes = node_load_multiple($nids);
99 }
100
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']);
106
107 return drupal_render($build);
108 }
109 }
110 }