Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / views_content / plugins / views / views_content_plugin_display_panel_pane.inc @ 219d19c4

1 85ad3d82 Assos Assos
<?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 219d19c4 Assos Assos
8 85ad3d82 Assos Assos
  /**
9
   * If this variable is true, this display counts as a panel pane. We use
10
   * this variable so that other modules can create alternate pane displays.
11
   */
12 c304a780 Assos Assos
  public $panel_pane_display = TRUE;
13
  public $has_pane_conf = NULL;
14 85ad3d82 Assos Assos
15 219d19c4 Assos Assos
  /**
16
   * {@inheritdoc}
17
   */
18 c304a780 Assos Assos
  public function option_definition() {
19 85ad3d82 Assos Assos
    $options = parent::option_definition();
20
21
    $options['pane_title'] = array('default' => '', 'translatable' => TRUE);
22
    $options['pane_description'] = array('default' => '', 'translatable' => TRUE);
23
    $options['pane_category'] = array(
24
      'contains' => array(
25
        'name' => array('default' => 'View panes', 'translatable' => TRUE),
26
        'weight' => array('default' => 0),
27
      ),
28
    );
29
30
    $options['allow'] = array(
31
      'contains' => array(
32
        'use_pager'       => array('default' => FALSE),
33
        'items_per_page'  => array('default' => FALSE),
34
        'offset'          => array('default' => FALSE),
35
        'link_to_view'    => array('default' => FALSE),
36
        'more_link'       => array('default' => FALSE),
37
        'path_override'   => array('default' => FALSE),
38
        'title_override'  => array('default' => FALSE),
39
        'exposed_form'    => array('default' => FALSE),
40
        'fields_override' => array('default' => FALSE),
41 c304a780 Assos Assos
      ),
42 85ad3d82 Assos Assos
    );
43
44
    $options['argument_input'] = array('default' => array());
45
    $options['link_to_view'] = array('default' => 0);
46
    $options['inherit_panels_path'] = array('default' => 0);
47
48
    return $options;
49
  }
50
51 c304a780 Assos Assos
52
  public function has_pane_conf() {
53 85ad3d82 Assos Assos
    return isset($this->has_pane_conf);
54
  }
55
56 c304a780 Assos Assos
57
  public function set_pane_conf($conf = array()) {
58 85ad3d82 Assos Assos
    $this->set_option('pane_conf', $conf);
59
    $this->has_pane_conf = TRUE;
60
  }
61
62
  /**
63
   * Provide the summary for page options in the views UI.
64
   *
65
   * This output is returned as an array.
66
   */
67 c304a780 Assos Assos
  public function options_summary(&$categories, &$options) {
68 85ad3d82 Assos Assos
    // It is very important to call the parent function here:
69
    parent::options_summary($categories, $options);
70
71
    $categories['panel_pane'] = array(
72
      'title' => t('Pane settings'),
73
      'column' => 'second',
74
      'build' => array(
75
        '#weight' => -10,
76
      ),
77
    );
78
79
    $pane_title = $this->get_option('pane_title');
80
    if (empty($pane_title)) {
81
      $pane_title = t('Use view name');
82
    }
83
84
    if (drupal_strlen($pane_title) > 16) {
85
      $pane_title = drupal_substr($pane_title, 0, 16) . '...';
86
    }
87
88
    $options['pane_title'] = array(
89
      'category' => 'panel_pane',
90
      'title' => t('Admin title'),
91
      'value' => $pane_title,
92
    );
93
94
    $pane_description = $this->get_option('pane_description');
95
    if (empty($pane_description)) {
96
      $pane_description = t('Use view description');
97
    }
98
99
    if (drupal_strlen($pane_description) > 16) {
100
      $pane_description = drupal_substr($pane_description, 0, 16) . '...';
101
    }
102
103
    $options['pane_description'] = array(
104
      'category' => 'panel_pane',
105
      'title' => t('Admin desc'),
106
      'value' => $pane_description,
107
    );
108
109
    $category = $this->get_option('pane_category');
110
    $pane_category = $category['name'];
111
    if (empty($pane_category)) {
112
      $pane_category = t('View panes');
113
    }
114
115
    if (drupal_strlen($pane_category) > 16) {
116
      $pane_category = drupal_substr($pane_category, 0, 16) . '...';
117
    }
118
119
    $options['pane_category'] = array(
120
      'category' => 'panel_pane',
121
      'title' => t('Category'),
122
      'value' => $pane_category,
123
    );
124
125
    $options['link_to_view'] = array(
126
      'category' => 'panel_pane',
127
      'title' => t('Link to view'),
128
      'value' => $this->get_option('link_to_view') ? t('Yes') : t('No'),
129
    );
130
131
    $options['inherit_panels_path'] = array(
132
      'category' => 'panel_pane',
133
      'title' => t('Use Panel path'),
134
      'value' => $this->get_option('inherit_panels_path') ? t('Yes') : t('No'),
135
    );
136
137
    $options['argument_input'] = array(
138
      'category' => 'panel_pane',
139
      'title' => t('Argument input'),
140
      'value' => t('Edit'),
141
    );
142
143
    $allow = $this->get_option('allow');
144
    $filtered_allow = array_filter($allow);
145
146
    $options['allow'] = array(
147
      'category' => 'panel_pane',
148
      'title' => t('Allow settings'),
149
      'value' => empty($filtered_allow) ? t('None') : ($allow === $filtered_allow ? t('All') : t('Some')),
150
    );
151
  }
152
153
  /**
154
   * Provide the default form for setting options.
155
   */
156 c304a780 Assos Assos
  public function options_form(&$form, &$form_state) {
157 85ad3d82 Assos Assos
    // It is very important to call the parent function here:
158
    parent::options_form($form, $form_state);
159
160
    switch ($form_state['section']) {
161
      case 'allow':
162
        $form['#title'] .= t('Allow settings');
163
        $form['description'] = array(
164
          '#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>',
165
        );
166
167
        $options = array(
168
          'use_pager' => t('Use pager'),
169
          'items_per_page' => t('Items per page'),
170
          'offset' => t('Pager offset'),
171
          'link_to_view' => t('Link to view'),
172
          'more_link' => t('More link'),
173
          'path_override' => t('Path override'),
174
          'title_override' => t('Title override'),
175
          'exposed_form' => t('Use exposed widgets form as pane configuration'),
176
          'fields_override' => t('Fields override'),
177
        );
178
179
        $allow = array_filter($this->get_option('allow'));
180
        $form['allow'] = array(
181
          '#type' => 'checkboxes',
182
          '#default_value' => $allow,
183
          '#options' => $options,
184
        );
185
        break;
186 c304a780 Assos Assos
187 85ad3d82 Assos Assos
      case 'pane_title':
188
        $form['#title'] .= t('Administrative title');
189
190
        $form['pane_title'] = array(
191
          '#type' => 'textfield',
192
          '#default_value' => $this->get_option('pane_title'),
193
          '#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.'),
194
        );
195
        break;
196
197
      case 'pane_description':
198
        $form['#title'] .= t('Administrative description');
199
200
        $form['pane_description'] = array(
201
          '#type' => 'textfield',
202
          '#default_value' => $this->get_option('pane_description'),
203
          '#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.'),
204
        );
205
        break;
206
207
      case 'pane_category':
208
        $form['#title'] .= t('Administrative description');
209
210
        $cat = $this->get_option('pane_category');
211
        $form['pane_category']['#tree'] = TRUE;
212
        $form['pane_category']['name'] = array(
213
          '#type' => 'textfield',
214
          '#default_value' => $cat['name'],
215
          '#description' => t('This is category the pane will appear in on the add content dialog.'),
216
        );
217
        $form['pane_category']['weight'] = array(
218
          '#title' => t('Weight'),
219
          '#type' => 'textfield',
220
          '#default_value' => $cat['weight'],
221
          '#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.'),
222
        );
223
        break;
224
225
      case 'link_to_view':
226
        $form['#title'] .= t('Link pane title to view');
227
228
        $form['link_to_view'] = array(
229
          '#type' => 'select',
230
          '#options' => array(1 => t('Yes'), 0 => t('No')),
231
          '#default_value' => $this->get_option('link_to_view'),
232
        );
233
        break;
234
235
      case 'inherit_panels_path':
236
        $form['#title'] .= t('Inherit path from panel display');
237
238
        $form['inherit_panels_path'] = array(
239
          '#type' => 'select',
240
          '#options' => array(1 => t('Yes'), 0 => t('No')),
241
          '#default_value' => $this->get_option('inherit_panels_path'),
242
          '#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.'),
243
        );
244
        break;
245
246
      case 'argument_input':
247
        $form['#title'] .= t('Choose the data source for view arguments');
248
        $argument_input = $this->get_argument_input();
249
        ctools_include('context');
250
        ctools_include('dependent');
251
        $form['argument_input']['#tree'] = TRUE;
252
253
        $converters = ctools_context_get_all_converters();
254
        ksort($converters);
255
256
        foreach ($argument_input as $id => $argument) {
257
          $form['argument_input'][$id] = array(
258
            '#tree' => TRUE,
259
          );
260
261
          $safe = str_replace(array('][', '_', ' '), '-', $id);
262
          $type_id = 'edit-argument-input-' . $safe;
263
264
          $form['argument_input'][$id]['type'] = array(
265
            '#type' => 'select',
266
            '#options' => array(
267
              'none' => t('No argument'),
268
              'wildcard' => t('Argument wildcard'),
269
              'context' => t('From context'),
270
              'panel' => t('From panel argument'),
271
              'fixed' => t('Fixed'),
272
              'user' => t('Input on pane config'),
273
            ),
274
            '#id' => $type_id,
275
            '#title' => t('@arg source', array('@arg' => $argument['name'])),
276
            '#default_value' => $argument['type'],
277
          );
278
          $form['argument_input'][$id]['context'] = array(
279
            '#type' => 'select',
280
            '#title' => t('Required context'),
281
            '#description' => t('If "From context" is selected, which type of context to use.'),
282
            '#default_value' => $argument['context'],
283
            '#options' => $converters,
284
            '#dependency' => array($type_id => array('context')),
285
          );
286
287
          $form['argument_input'][$id]['context_optional'] = array(
288
            '#type' => 'checkbox',
289
            '#title' => t('Context is optional'),
290
            '#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.'),
291
            '#default_value' => $argument['context_optional'],
292
            '#dependency' => array($type_id => array('context')),
293
          );
294
295
          $form['argument_input'][$id]['panel'] = array(
296
            '#type' => 'select',
297
            '#title' => t('Panel argument'),
298
            '#description' => t('If "From panel argument" is selected, which panel argument to use.'),
299
            '#default_value' => $argument['panel'],
300
            '#options' => array(0 => t('First'), 1 => t('Second'), 2 => t('Third'), 3 => t('Fourth'), 4 => t('Fifth'), 5 => t('Sixth')),
301
            '#dependency' => array($type_id => array('panel')),
302
          );
303
304
          $form['argument_input'][$id]['fixed'] = array(
305
            '#type' => 'textfield',
306
            '#title' => t('Fixed argument'),
307
            '#description' => t('If "Fixed" is selected, what to use as an argument.'),
308
            '#default_value' => $argument['fixed'],
309
            '#dependency' => array($type_id => array('fixed')),
310
          );
311
312
          $form['argument_input'][$id]['label'] = array(
313
            '#type' => 'textfield',
314
            '#title' => t('Label'),
315
            '#description' => t('If this argument is presented to the panels user, what label to apply to it.'),
316
            '#default_value' => empty($argument['label']) ? $argument['name'] : $argument['label'],
317
            '#dependency' => array($type_id => array('user')),
318
          );
319
        }
320
        break;
321
    }
322
  }
323
324
  /**
325
   * Perform any necessary changes to the form values prior to storage.
326
   * There is no need for this function to actually store the data.
327
   */
328 c304a780 Assos Assos
  public function options_submit(&$form, &$form_state) {
329 85ad3d82 Assos Assos
    // It is very important to call the parent function here:
330
    parent::options_submit($form, $form_state);
331
    switch ($form_state['section']) {
332
      case 'allow':
333
      case 'argument_input':
334
      case 'link_to_view':
335
      case 'inherit_panels_path':
336
      case 'pane_title':
337
      case 'pane_description':
338
      case 'pane_category':
339
        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
340
        break;
341
    }
342
  }
343
344
  /**
345
   * Adjust the array of argument input to match the current list of
346
   * arguments available for this display. This ensures that changing
347
   * the arguments doesn't cause the argument input field to just
348
   * break.
349
   */
350 c304a780 Assos Assos
  public function get_argument_input() {
351 85ad3d82 Assos Assos
    $arguments = $this->get_option('argument_input');
352
    $handlers = $this->get_handlers('argument');
353
354
    // We use a separate output so as to seamlessly discard info for
355
    // arguments that no longer exist.
356
    $output = array();
357
358
    foreach ($handlers as $id => $handler) {
359
      if (empty($arguments[$id])) {
360
        $output[$id] = array(
361
          'type' => 'none',
362
          'context' => 'any',
363
          'context_optional' => FALSE,
364
          'panel' => 0,
365
          'fixed' => '',
366
          'name' => $handler->ui_name(),
367
        );
368
      }
369
      else {
370
        $output[$id] = $arguments[$id];
371
        $output[$id]['name'] = $handler->ui_name();
372
      }
373
    }
374
375
    return $output;
376
  }
377
378 c304a780 Assos Assos
379
  public function use_more() {
380 85ad3d82 Assos Assos
    $allow = $this->get_option('allow');
381
    if (!$allow['more_link'] || !$this->has_pane_conf()) {
382
      return parent::use_more();
383
    }
384
    $conf = $this->get_option('pane_conf');
385
    return (bool) $conf['more_link'];
386
  }
387
388 219d19c4 Assos Assos
  /**
389
   * {@inheritdoc}
390
   */
391
  public function has_path() {
392
    return TRUE;
393
  }
394
395
  /**
396
   * {@inheritdoc}
397
   */
398
  public function validate() {
399
    // To bypass the validation of the path from Views we temporarily
400
    // override the path if one doesn't exist because it will be generated
401
    // by panels though we want the rest of the validations to run.
402
    $path = $this->get_path();
403
    if (!$path) {
404
      $this->set_option('path', $_GET['q']);
405
    }
406
407
    return parent::validate();
408
  }
409 c304a780 Assos Assos
410 219d19c4 Assos Assos
  /**
411
   * {@inheritdoc}
412
   */
413 c304a780 Assos Assos
  public function get_path() {
414 85ad3d82 Assos Assos
    if (empty($this->view->override_path)) {
415
      return parent::get_path();
416
    }
417
    return $this->view->override_path;
418
  }
419
420 c304a780 Assos Assos
421
  public function get_url() {
422 85ad3d82 Assos Assos
    if ($this->get_option('inherit_panels_path')) {
423
      return $this->get_path();
424
    }
425
    return parent::get_url();
426
  }
427
428 c304a780 Assos Assos
429
  public function uses_exposed_form_in_block() {
430 85ad3d82 Assos Assos
    // We'll always allow the exposed form in a block, regardless of path.
431
    return TRUE;
432
  }
433
434
  /**
435
   * Determine if this display should display the exposed
436
   * filters widgets, so the view will know whether or not
437
   * to render them.
438
   *
439
   * Regardless of what this function
440
   * returns, exposed filters will not be used nor
441
   * displayed unless uses_exposed() returns TRUE.
442
   */
443 c304a780 Assos Assos
  public function displays_exposed() {
444 85ad3d82 Assos Assos
    $conf = $this->get_option('allow');
445
    // If this is set, the exposed form is part of pane configuration, not
446
    // rendered normally.
447
    return empty($conf['exposed_form']);
448
  }
449
450
}