Projet

Général

Profil

Paste
Télécharger (5,46 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_wizard / views_ui_node_views_wizard.class.php @ 13c3c9b4

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of ViewsUiNodeViewsWizard.
6
 */
7

    
8
/**
9
 * Tests creating node views with the wizard.
10
 */
11
class ViewsUiNodeViewsWizard extends ViewsUiBaseViewsWizard {
12

    
13
  protected function row_style_options($type) {
14
    $options = array();
15
    $options['teasers'] = t('teasers');
16
    $options['full_posts'] = t('full posts');
17
    $options['titles'] = t('titles');
18
    $options['titles_linked'] = t('titles (linked)');
19
    $options['fields'] = t('fields');
20
    return $options;
21
  }
22

    
23
  protected function build_form_style(&$form, &$form_state, $type) {
24
    parent::build_form_style($form, $form_state, $type);
25
    $style_form =& $form['displays'][$type]['options']['style'];
26
    // Some style plugins don't support row plugins so stop here if that's the
27
    // case.
28
    if (!isset($style_form['row_plugin']['#default_value'])) {
29
      return;
30
    }
31
    $row_plugin = $style_form['row_plugin']['#default_value'];
32
    switch ($row_plugin) {
33
      case 'full_posts':
34
      case 'teasers':
35
        $style_form['row_options']['links'] = array(
36
          '#type' => 'select',
37
          '#title_display' => 'invisible',
38
          '#title' => t('Should links be displayed below each node'),
39
          '#options' => array(
40
            1 => t('with links (allow users to add comments, etc.)'),
41
            0 => t('without links'),
42
          ),
43
          '#default_value' => 1,
44
        );
45
        $style_form['row_options']['comments'] = array(
46
          '#type' => 'select',
47
          '#title_display' => 'invisible',
48
          '#title' => t('Should comments be displayed below each node'),
49
          '#options' => array(
50
            1 => t('with comments'),
51
            0 => t('without comments'),
52
          ),
53
          '#default_value' => 0,
54
        );
55
        break;
56
    }
57
  }
58

    
59
  /**
60
   * @override
61
   */
62
  protected function default_display_options($form, $form_state) {
63
    $display_options = parent::default_display_options($form, $form_state);
64

    
65
    // Add permission-based access control.
66
    $display_options['access']['type'] = 'perm';
67
    $display_options['access']['perm'] = 'access content';
68

    
69
    // Remove the default fields, since we are customizing them here.
70
    unset($display_options['fields']);
71

    
72
    // Add the title field, so that the display has content if the user switches
73
    // to a row style that uses fields.
74
    /* Field: Content: Title */
75
    $display_options['fields']['title']['id'] = 'title';
76
    $display_options['fields']['title']['table'] = 'node';
77
    $display_options['fields']['title']['field'] = 'title';
78
    $display_options['fields']['title']['label'] = '';
79
    $display_options['fields']['title']['alter']['alter_text'] = 0;
80
    $display_options['fields']['title']['alter']['make_link'] = 0;
81
    $display_options['fields']['title']['alter']['absolute'] = 0;
82
    $display_options['fields']['title']['alter']['trim'] = 0;
83
    $display_options['fields']['title']['alter']['word_boundary'] = 0;
84
    $display_options['fields']['title']['alter']['ellipsis'] = 0;
85
    $display_options['fields']['title']['alter']['strip_tags'] = 0;
86
    $display_options['fields']['title']['alter']['html'] = 0;
87
    $display_options['fields']['title']['hide_empty'] = 0;
88
    $display_options['fields']['title']['empty_zero'] = 0;
89
    $display_options['fields']['title']['link_to_node'] = 1;
90

    
91
    return $display_options;
92
  }
93

    
94
  protected function page_display_options($form, $form_state) {
95
    $display_options = parent::page_display_options($form, $form_state);
96
    $row_plugin = isset($form_state['values']['page']['style']['row_plugin']) ? $form_state['values']['page']['style']['row_plugin'] : NULL;
97
    $row_options = isset($form_state['values']['page']['style']['row_options']) ? $form_state['values']['page']['style']['row_options'] : array();
98
    $this->display_options_row($display_options, $row_plugin, $row_options);
99
    return $display_options;
100
  }
101

    
102
  protected function block_display_options($form, $form_state) {
103
    $display_options = parent::block_display_options($form, $form_state);
104
    $row_plugin = isset($form_state['values']['block']['style']['row_plugin']) ? $form_state['values']['block']['style']['row_plugin'] : NULL;
105
    $row_options = isset($form_state['values']['block']['style']['row_options']) ? $form_state['values']['block']['style']['row_options'] : array();
106
    $this->display_options_row($display_options, $row_plugin, $row_options);
107
    return $display_options;
108
  }
109

    
110
  /**
111
   * Set the row style and row style plugins to the display_options.
112
   */
113
  protected  function display_options_row(&$display_options, $row_plugin, $row_options) {
114
    switch ($row_plugin) {
115
      case 'full_posts':
116
        $display_options['row_plugin'] = 'node';
117
        $display_options['row_options']['build_mode'] = 'full';
118
        $display_options['row_options']['links'] = !empty($row_options['links']);
119
        $display_options['row_options']['comments'] = !empty($row_options['comments']);
120
        break;
121
      case 'teasers':
122
        $display_options['row_plugin'] = 'node';
123
        $display_options['row_options']['build_mode'] = 'teaser';
124
        $display_options['row_options']['links'] = !empty($row_options['links']);
125
        $display_options['row_options']['comments'] = !empty($row_options['comments']);
126
        break;
127
      case 'titles_linked':
128
        $display_options['row_plugin'] = 'fields';
129
        $display_options['field']['title']['link_to_node'] = 1;
130
        break;
131
      case 'titles':
132
        $display_options['row_plugin'] = 'fields';
133
        $display_options['field']['title']['link_to_node'] = 0;
134
        break;
135
    }
136
  }
137
}