Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / views_content / plugins / views / views_content_plugin_display_panel_pane.inc @ 7e72b748

1
<?php
2

    
3
/**
4
 * The plugin that handles a panel_pane.
5
 */
6
class views_content_plugin_display_panel_pane extends views_plugin_display {
7
  /**
8
   * If this variable is true, this display counts as a panel pane. We use
9
   * this variable so that other modules can create alternate pane displays.
10
   */
11
  var $panel_pane_display = TRUE;
12
  var $has_pane_conf = NULL;
13

    
14
  function option_definition() {
15
    $options = parent::option_definition();
16

    
17
    $options['pane_title'] = array('default' => '', 'translatable' => TRUE);
18
    $options['pane_description'] = array('default' => '', 'translatable' => TRUE);
19
    $options['pane_category'] = array(
20
      'contains' => array(
21
        'name' => array('default' => 'View panes', 'translatable' => TRUE),
22
        'weight' => array('default' => 0),
23
      ),
24
    );
25

    
26
    $options['allow'] = array(
27
      'contains' => array(
28
        'use_pager'       => array('default' => FALSE),
29
        'items_per_page'  => array('default' => FALSE),
30
        'offset'          => array('default' => FALSE),
31
        'link_to_view'    => array('default' => FALSE),
32
        'more_link'       => array('default' => FALSE),
33
        'path_override'   => array('default' => FALSE),
34
        'title_override'  => array('default' => FALSE),
35
        'exposed_form'    => array('default' => FALSE),
36
        'fields_override' => array('default' => FALSE),
37
       ),
38
    );
39

    
40
    $options['argument_input'] = array('default' => array());
41
    $options['link_to_view'] = array('default' => 0);
42
    $options['inherit_panels_path'] = array('default' => 0);
43

    
44
    return $options;
45
  }
46

    
47
  function has_pane_conf() {
48
    return isset($this->has_pane_conf);
49
  }
50

    
51
  function set_pane_conf($conf = array()) {
52
    $this->set_option('pane_conf', $conf);
53
    $this->has_pane_conf = TRUE;
54
  }
55

    
56
  /**
57
   * Provide the summary for page options in the views UI.
58
   *
59
   * This output is returned as an array.
60
   */
61
  function options_summary(&$categories, &$options) {
62
    // It is very important to call the parent function here:
63
    parent::options_summary($categories, $options);
64

    
65
    $categories['panel_pane'] = array(
66
      'title' => t('Pane settings'),
67
      'column' => 'second',
68
      'build' => array(
69
        '#weight' => -10,
70
      ),
71
    );
72

    
73
    $pane_title = $this->get_option('pane_title');
74
    if (empty($pane_title)) {
75
      $pane_title = t('Use view name');
76
    }
77

    
78
    if (drupal_strlen($pane_title) > 16) {
79
      $pane_title = drupal_substr($pane_title, 0, 16) . '...';
80
    }
81

    
82
    $options['pane_title'] = array(
83
      'category' => 'panel_pane',
84
      'title' => t('Admin title'),
85
      'value' => $pane_title,
86
    );
87

    
88
    $pane_description = $this->get_option('pane_description');
89
    if (empty($pane_description)) {
90
      $pane_description = t('Use view description');
91
    }
92

    
93
    if (drupal_strlen($pane_description) > 16) {
94
      $pane_description = drupal_substr($pane_description, 0, 16) . '...';
95
    }
96

    
97
    $options['pane_description'] = array(
98
      'category' => 'panel_pane',
99
      'title' => t('Admin desc'),
100
      'value' => $pane_description,
101
    );
102

    
103
    $category = $this->get_option('pane_category');
104
    $pane_category = $category['name'];
105
    if (empty($pane_category)) {
106
      $pane_category = t('View panes');
107
    }
108

    
109
    if (drupal_strlen($pane_category) > 16) {
110
      $pane_category = drupal_substr($pane_category, 0, 16) . '...';
111
    }
112

    
113
    $options['pane_category'] = array(
114
      'category' => 'panel_pane',
115
      'title' => t('Category'),
116
      'value' => $pane_category,
117
    );
118

    
119
    $options['link_to_view'] = array(
120
      'category' => 'panel_pane',
121
      'title' => t('Link to view'),
122
      'value' => $this->get_option('link_to_view') ? t('Yes') : t('No'),
123
    );
124

    
125
    $options['inherit_panels_path'] = array(
126
      'category' => 'panel_pane',
127
      'title' => t('Use Panel path'),
128
      'value' => $this->get_option('inherit_panels_path') ? t('Yes') : t('No'),
129
    );
130

    
131
    $options['argument_input'] = array(
132
      'category' => 'panel_pane',
133
      'title' => t('Argument input'),
134
      'value' => t('Edit'),
135
    );
136

    
137
    $allow = $this->get_option('allow');
138
    $filtered_allow = array_filter($allow);
139

    
140
    $options['allow'] = array(
141
      'category' => 'panel_pane',
142
      'title' => t('Allow settings'),
143
      'value' => empty($filtered_allow) ? t('None') : ($allow === $filtered_allow ? t('All') : t('Some')),
144
    );
145
  }
146

    
147
  /**
148
   * Provide the default form for setting options.
149
   */
150
  function options_form(&$form, &$form_state) {
151
    // It is very important to call the parent function here:
152
    parent::options_form($form, $form_state);
153

    
154
    switch ($form_state['section']) {
155
      case 'allow':
156
        $form['#title'] .= t('Allow settings');
157
        $form['description'] = array(
158
          '#value' => '<div class="form-item description">' . t('Checked settings will be available in the panel pane config dialog for modification by the panels user. Unchecked settings will not be available and will only use the settings in this display.') . '</div>',
159
        );
160

    
161
        $options = array(
162
          'use_pager' => t('Use pager'),
163
          'items_per_page' => t('Items per page'),
164
          'offset' => t('Pager offset'),
165
          'link_to_view' => t('Link to view'),
166
          'more_link' => t('More link'),
167
          'path_override' => t('Path override'),
168
          'title_override' => t('Title override'),
169
          'exposed_form' => t('Use exposed widgets form as pane configuration'),
170
          'fields_override' => t('Fields override'),
171
        );
172

    
173
        $allow = array_filter($this->get_option('allow'));
174
        $form['allow'] = array(
175
          '#type' => 'checkboxes',
176
          '#default_value' => $allow,
177
          '#options' => $options,
178
        );
179
        break;
180
      case 'pane_title':
181
        $form['#title'] .= t('Administrative title');
182

    
183
        $form['pane_title'] = array(
184
          '#type' => 'textfield',
185
          '#default_value' => $this->get_option('pane_title'),
186
          '#description' => t('This is the title that will appear for this view pane in the add content dialog. If left blank, the view name will be used.'),
187
        );
188
        break;
189

    
190
      case 'pane_description':
191
        $form['#title'] .= t('Administrative description');
192

    
193
        $form['pane_description'] = array(
194
          '#type' => 'textfield',
195
          '#default_value' => $this->get_option('pane_description'),
196
          '#description' => t('This is text that will be displayed when the user mouses over the pane in the add content dialog. If blank the view description will be used.'),
197
        );
198
        break;
199

    
200
      case 'pane_category':
201
        $form['#title'] .= t('Administrative description');
202

    
203
        $cat = $this->get_option('pane_category');
204
        $form['pane_category']['#tree'] = TRUE;
205
        $form['pane_category']['name'] = array(
206
          '#type' => 'textfield',
207
          '#default_value' => $cat['name'],
208
          '#description' => t('This is category the pane will appear in on the add content dialog.'),
209
        );
210
        $form['pane_category']['weight'] = array(
211
          '#title' => t('Weight'),
212
          '#type' => 'textfield',
213
          '#default_value' => $cat['weight'],
214
          '#description' => t('This is the default weight of the category. Note that if the weight of a category is defined in multiple places, only the first one Panels sees will get that definition, so if the weight does not appear to be working, check other places that the weight might be set.'),
215
        );
216
        break;
217

    
218
      case 'link_to_view':
219
        $form['#title'] .= t('Link pane title to view');
220

    
221
        $form['link_to_view'] = array(
222
          '#type' => 'select',
223
          '#options' => array(1 => t('Yes'), 0 => t('No')),
224
          '#default_value' => $this->get_option('link_to_view'),
225
        );
226
        break;
227

    
228
      case 'inherit_panels_path':
229
        $form['#title'] .= t('Inherit path from panel display');
230

    
231
        $form['inherit_panels_path'] = array(
232
          '#type' => 'select',
233
          '#options' => array(1 => t('Yes'), 0 => t('No')),
234
          '#default_value' => $this->get_option('inherit_panels_path'),
235
          '#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.'),
236
        );
237
        break;
238

    
239
      case 'argument_input':
240
        $form['#title'] .= t('Choose the data source for view arguments');
241
        $argument_input = $this->get_argument_input();
242
        ctools_include('context');
243
        ctools_include('dependent');
244
        $form['argument_input']['#tree'] = TRUE;
245

    
246
        $converters = ctools_context_get_all_converters();
247
        ksort($converters);
248

    
249
        foreach ($argument_input as $id => $argument) {
250
          $form['argument_input'][$id] = array(
251
            '#tree' => TRUE,
252
          );
253

    
254
          $safe = str_replace(array('][', '_', ' '), '-', $id);
255
          $type_id = 'edit-argument-input-' . $safe;
256

    
257
          $form['argument_input'][$id]['type'] = array(
258
            '#type' => 'select',
259
            '#options' => array(
260
              'none' => t('No argument'),
261
              'wildcard' => t('Argument wildcard'),
262
              'context' => t('From context'),
263
              'panel' => t('From panel argument'),
264
              'fixed' => t('Fixed'),
265
              'user' => t('Input on pane config'),
266
            ),
267
            '#id' => $type_id,
268
            '#title' => t('@arg source', array('@arg' => $argument['name'])),
269
            '#default_value' => $argument['type'],
270
          );
271
          $form['argument_input'][$id]['context'] = array(
272
            '#type' => 'select',
273
            '#title' => t('Required context'),
274
            '#description' => t('If "From context" is selected, which type of context to use.'),
275
            '#default_value' => $argument['context'],
276
            '#options' => $converters,
277
            '#dependency' => array($type_id => array('context')),
278
          );
279

    
280
          $form['argument_input'][$id]['context_optional'] = array(
281
            '#type' => 'checkbox',
282
            '#title' => t('Context is optional'),
283
            '#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.'),
284
            '#default_value' => $argument['context_optional'],
285
            '#dependency' => array($type_id => array('context')),
286
          );
287

    
288
          $form['argument_input'][$id]['panel'] = array(
289
            '#type' => 'select',
290
            '#title' => t('Panel argument'),
291
            '#description' => t('If "From panel argument" is selected, which panel argument to use.'),
292
            '#default_value' => $argument['panel'],
293
            '#options' => array(0 => t('First'), 1 => t('Second'), 2 => t('Third'), 3 => t('Fourth'), 4 => t('Fifth'), 5 => t('Sixth')),
294
            '#dependency' => array($type_id => array('panel')),
295
          );
296

    
297
          $form['argument_input'][$id]['fixed'] = array(
298
            '#type' => 'textfield',
299
            '#title' => t('Fixed argument'),
300
            '#description' => t('If "Fixed" is selected, what to use as an argument.'),
301
            '#default_value' => $argument['fixed'],
302
            '#dependency' => array($type_id => array('fixed')),
303
          );
304

    
305
          $form['argument_input'][$id]['label'] = array(
306
            '#type' => 'textfield',
307
            '#title' => t('Label'),
308
            '#description' => t('If this argument is presented to the panels user, what label to apply to it.'),
309
            '#default_value' => empty($argument['label']) ? $argument['name'] : $argument['label'],
310
            '#dependency' => array($type_id => array('user')),
311
          );
312
        }
313
        break;
314
    }
315
  }
316

    
317
  /**
318
   * Perform any necessary changes to the form values prior to storage.
319
   * There is no need for this function to actually store the data.
320
   */
321
  function options_submit(&$form, &$form_state) {
322
    // It is very important to call the parent function here:
323
    parent::options_submit($form, $form_state);
324
    switch ($form_state['section']) {
325
      case 'allow':
326
      case 'argument_input':
327
      case 'link_to_view':
328
      case 'inherit_panels_path':
329
      case 'pane_title':
330
      case 'pane_description':
331
      case 'pane_category':
332
        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
333
        break;
334
    }
335
  }
336

    
337
  /**
338
   * Adjust the array of argument input to match the current list of
339
   * arguments available for this display. This ensures that changing
340
   * the arguments doesn't cause the argument input field to just
341
   * break.
342
   */
343
  function get_argument_input() {
344
    $arguments = $this->get_option('argument_input');
345
    $handlers = $this->get_handlers('argument');
346

    
347
    // We use a separate output so as to seamlessly discard info for
348
    // arguments that no longer exist.
349
    $output = array();
350

    
351
    foreach ($handlers as $id => $handler) {
352
      if (empty($arguments[$id])) {
353
        $output[$id] = array(
354
          'type' => 'none',
355
          'context' => 'any',
356
          'context_optional' => FALSE,
357
          'panel' => 0,
358
          'fixed' => '',
359
          'name' => $handler->ui_name(),
360
        );
361
      }
362
      else {
363
        $output[$id] = $arguments[$id];
364
        $output[$id]['name'] = $handler->ui_name();
365
      }
366
    }
367

    
368
    return $output;
369
  }
370

    
371
  function use_more() {
372
    $allow = $this->get_option('allow');
373
    if (!$allow['more_link'] || !$this->has_pane_conf()) {
374
      return parent::use_more();
375
    }
376
    $conf = $this->get_option('pane_conf');
377
    return (bool) $conf['more_link'];
378
  }
379

    
380
  function get_path() {
381
    if (empty($this->view->override_path)) {
382
      return parent::get_path();
383
    }
384
    return $this->view->override_path;
385
  }
386

    
387
  function get_url() {
388
    if ($this->get_option('inherit_panels_path')) {
389
      return $this->get_path();
390
    }
391
    return parent::get_url();
392
  }
393

    
394
  function uses_exposed_form_in_block() {
395
    // We'll always allow the exposed form in a block, regardless of path.
396
    return TRUE;
397
  }
398

    
399
  /**
400
   * Determine if this display should display the exposed
401
   * filters widgets, so the view will know whether or not
402
   * to render them.
403
   *
404
   * Regardless of what this function
405
   * returns, exposed filters will not be used nor
406
   * displayed unless uses_exposed() returns TRUE.
407
   */
408
  function displays_exposed() {
409
    $conf = $this->get_option('allow');
410
    // If this is set, the exposed form is part of pane configuration, not
411
    // rendered normally.
412
    return empty($conf['exposed_form']);
413
  }
414

    
415
}
416