Projet

Général

Profil

Paste
Télécharger (3,06 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / node / views_plugin_row_node_view.inc @ ef1afbb9

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
      '#access' => module_exists('comment'),
65
    );
66
  }
67

    
68
  /**
69
   * Return the main options, which are shown in the summary title.
70
   */
71
  function options_form_summary_options() {
72
    $entity_info = entity_get_info('node');
73
    $options = array();
74
    if (!empty($entity_info['view modes'])) {
75
      foreach ($entity_info['view modes'] as $mode => $settings) {
76
        $options[$mode] = $settings['label'];
77
      }
78
    }
79
    if (empty($options)) {
80
      $options = array(
81
        'teaser' => t('Teaser'),
82
        'full' => t('Full content')
83
      );
84
    }
85

    
86
    return $options;
87
  }
88

    
89
  function summary_title() {
90
    $options = $this->options_form_summary_options();
91
    return check_plain($options[$this->options['view_mode']]);
92
  }
93

    
94
  function pre_render($values) {
95
    $nids = array();
96
    foreach ($values as $row) {
97
      $nids[] = $row->{$this->field_alias};
98
    }
99
    $this->nodes = node_load_multiple($nids);
100
  }
101

    
102
  function render($row) {
103
    if (isset($this->nodes[$row->{$this->field_alias}])) {
104
      $node = $this->nodes[$row->{$this->field_alias}];
105
      $node->view = $this->view;
106
      $build = node_view($node, $this->options['view_mode']);
107

    
108
      return drupal_render($build);
109
    }
110
  }
111
}