Projet

Général

Profil

Paste
Télécharger (8,88 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / views_content / plugins / views / views_content_plugin_display_ctools_context.inc @ e4c061ad

1
<?php
2
/**
3
 * @file
4
 * Contains the block display plugin.
5
 */
6

    
7
/**
8
 * The plugin that handles a block.
9
 *
10
 * @ingroup views_display_plugins
11
 */
12
class views_content_plugin_display_ctools_context extends views_plugin_display {
13
  /**
14
   * If this variable is true, this display counts as a context. We use this
15
   * variable so that we can easily build plugins against this display type.
16
   */
17
  var $context_display = TRUE;
18

    
19
  function get_style_type() { return 'context'; }
20

    
21
  function defaultable_sections($section = NULL) {
22
    if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) {
23
      return FALSE;
24
    }
25

    
26
    return parent::defaultable_sections($section);
27
  }
28

    
29
  function option_definition() {
30
    $options = parent::option_definition();
31

    
32
    $options['admin_title'] = array('default' => '', 'translatable' => TRUE);
33

    
34
    // Overrides for standard stuff:
35
    $options['style_plugin']['default'] = 'ctools_context';
36
    $options['row_plugin']['default'] = 'fields';
37
    $options['defaults']['default']['style_plugin'] = FALSE;
38
    $options['defaults']['default']['style_options'] = FALSE;
39
    $options['defaults']['default']['row_plugin'] = FALSE;
40
    $options['defaults']['default']['row_options'] = FALSE;
41
    $options['inherit_panels_path'] = array('default' => 0);
42
    $options['argument_input'] = array('default' => array());
43

    
44
    return $options;
45
  }
46

    
47
  /**
48
   * The display block handler returns the structure necessary for a block.
49
   */
50
  function execute() {
51
    $this->executing = TRUE;
52
    return $this->view->render();
53
  }
54

    
55
  function preview() {
56
    $this->previewing = TRUE;
57
    return $this->view->render();
58
  }
59

    
60
  /**
61
   * Render this display.
62
   */
63
  function render() {
64
    if (!empty($this->previewing)) {
65
      return theme($this->theme_functions(), array('view' => $this->view));
66
    }
67
    else {
68
      // We want to process the view like we're theming it, but not actually
69
      // use the template part. Therefore we run through all the preprocess
70
      // functions which will populate the variables array.
71
      $hooks = theme_get_registry();
72
      $info = $hooks[$this->definition['theme']];
73
      if (!empty($info['file'])) {
74
        @include_once('./' . $info['path'] . '/' . $info['file']);
75
      }
76
      $this->variables = array('view' => &$this->view);
77

    
78
      if (isset($info['preprocess functions']) && is_array($info['preprocess functions'])) {
79
        foreach ($info['preprocess functions'] as $preprocess_function) {
80
          if (function_exists($preprocess_function)) {
81
            $preprocess_function($this->variables, $this->definition['theme']);
82
          }
83
        }
84
      }
85
    }
86

    
87
    return $this->variables;
88
  }
89

    
90
  /**
91
   * Provide the summary for page options in the views UI.
92
   *
93
   * This output is returned as an array.
94
   */
95
  function options_summary(&$categories, &$options) {
96
    // It is very important to call the parent function here:
97
    parent::options_summary($categories, $options);
98

    
99
    $categories['context'] = array(
100
      'title' => t('Context settings'),
101
      'column' => 'second',
102
      'build' => array(
103
        '#weight' => -10,
104
      ),
105
    );
106

    
107
    $admin_title = $this->get_option('admin_title');
108
    if (empty($admin_title)) {
109
      $admin_title = t('Use view name');
110
    }
111

    
112
    if (drupal_strlen($admin_title) > 16) {
113
      $admin_title = drupal_substr($admin_title, 0, 16) . '...';
114
    }
115

    
116
    $options['admin_title'] = array(
117
      'category' => 'context',
118
      'title' => t('Admin title'),
119
      'value' => $admin_title,
120
    );
121

    
122
    $options['inherit_panels_path'] = array(
123
      'category' => 'context',
124
      'title' => t('Use Panel path'),
125
      'value' => $this->get_option('inherit_panels_path') ? t('Yes') : t('No'),
126
    );
127

    
128
    $options['argument_input'] = array(
129
      'category' => 'context',
130
      'title' => t('Argument input'),
131
      'value' => t('Edit'),
132
    );
133
  }
134

    
135
  /**
136
   * Provide the default form for setting options.
137
   */
138
  function options_form(&$form, &$form_state) {
139
    // It is very important to call the parent function here:
140
    parent::options_form($form, $form_state);
141
    switch ($form_state['section']) {
142
      case 'row_plugin':
143
        // This just overwrites the existing row_plugin which is using the wrong options.
144
        $form['row_plugin']['#options'] = views_fetch_plugin_names('row', 'normal', array($this->view->base_table));
145
        break;
146
      case 'admin_title':
147
        $form['#title'] .= t('Administrative title');
148

    
149
        $form['admin_title'] = array(
150
          '#type' => 'textfield',
151
          '#default_value' => $this->get_option('admin_title'),
152
          '#description' => t('This is the title that will appear for this view context in the configure context dialog. If left blank, the view name will be used.'),
153
        );
154
        break;
155
      case 'inherit_panels_path':
156
        $form['#title'] .= t('Inherit path from panel display');
157

    
158
        $form['inherit_panels_path'] = array(
159
          '#type' => 'select',
160
          '#options' => array(1 => t('Yes'), 0 => t('No')),
161
          '#default_value' => $this->get_option('inherit_panels_path'),
162
          '#description' => t('If yes, all links generated by Views, such as more links, summary links, and exposed input links will go to the panels display path, not the view, if the display has a path.'),
163
        );
164
        break;
165
      case 'argument_input':
166
        $form['#title'] .= t('Choose the data source for view arguments');
167
        $argument_input = $this->get_argument_input();
168
        ctools_include('context');
169
        ctools_include('dependent');
170
        $form['argument_input']['#tree'] = TRUE;
171

    
172
        $converters = ctools_context_get_all_converters();
173
        ksort($converters);
174

    
175
        foreach ($argument_input as $id => $argument) {
176
          $form['argument_input'][$id] = array(
177
            '#tree' => TRUE,
178
          );
179

    
180
          $safe = str_replace(array('][', '_', ' ', ':'), '-', $id);
181
          $type_id = 'edit-argument-input-' . $safe;
182

    
183
          $form['argument_input'][$id]['type'] = array(
184
            '#type' => 'select',
185
            '#options' => array(
186
              'none' => t('No argument'),
187
              'context' => t('From context'),
188
            ),
189
            '#id' => $type_id,
190
            '#title' => t('@arg source', array('@arg' => $argument['name'])),
191
            '#default_value' => $argument['type'],
192
          );
193

    
194
          $form['argument_input'][$id]['context'] = array(
195
            '#type' => 'select',
196
            '#title' => t('Required context'),
197
            '#description' => t('If "From context" is selected, which type of context to use.'),
198
            '#default_value' => $argument['context'],
199
            '#options' => $converters,
200
            '#dependency' => array($type_id => array('context')),
201
          );
202

    
203
          $form['argument_input'][$id]['context_optional'] = array(
204
            '#type' => 'checkbox',
205
            '#title' => t('Context is optional'),
206
            '#description' => t('This context need not be present for the pane to function. If you plan to use this, ensure that the argument handler can handle empty values gracefully.'),
207
            '#default_value' => $argument['context_optional'],
208
            '#dependency' => array($type_id => array('context')),
209
          );
210
        }
211
        break;
212
    }
213
  }
214

    
215
  /**
216
   * Perform any necessary changes to the form values prior to storage.
217
   * There is no need for this function to actually store the data.
218
   */
219
  function options_submit(&$form, &$form_state) {
220
    // It is very important to call the parent function here:
221
    parent::options_submit($form, $form_state);
222
    switch ($form_state['section']) {
223
      case 'admin_title':
224
      case 'argument_input':
225
      case 'inherit_panels_path':
226
        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
227
        break;
228
    }
229
  }
230

    
231
  /**
232
   * Adjust the array of argument input to match the current list of
233
   * arguments available for this display. This ensures that changing
234
   * the arguments doesn't cause the argument input field to just
235
   * break.
236
   */
237
  function get_argument_input() {
238
    $arguments = $this->get_option('argument_input');
239
    $handlers = $this->get_handlers('argument');
240

    
241
    // We use a separate output so as to seamlessly discard info for
242
    // arguments that no longer exist.
243
    $output = array();
244

    
245
    foreach ($handlers as $id => $handler) {
246
      if (empty($arguments[$id])) {
247
        $output[$id] = array(
248
          'type' => 'none',
249
          'context' => 'any',
250
          'context_optional' => FALSE,
251
          'name' => $handler->ui_name(),
252
        );
253
      }
254
      else {
255
        $output[$id] = $arguments[$id];
256
        $output[$id]['name'] = $handler->ui_name();
257
      }
258
    }
259

    
260
    return $output;
261
  }
262

    
263
  function get_path() {
264
    if ($this->get_option('link_display') == 'custom_url' && $override_path = $this->get_option('link_url')) {
265
      return $override_path;
266
    }
267
    if ($this->get_option('inherit_panels_path')) {
268
      return $_GET['q'];
269
    }
270
    return parent::get_path();
271
  }
272
}