Projet

Général

Profil

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

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

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
  public $panel_pane_display = TRUE;
12
  public $has_pane_conf = NULL;
13

    
14

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

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

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

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

    
45
    return $options;
46
  }
47

    
48

    
49
  public function has_pane_conf() {
50
    return isset($this->has_pane_conf);
51
  }
52

    
53

    
54
  public function set_pane_conf($conf = array()) {
55
    $this->set_option('pane_conf', $conf);
56
    $this->has_pane_conf = TRUE;
57
  }
58

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

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

    
76
    $pane_title = $this->get_option('pane_title');
77
    if (empty($pane_title)) {
78
      $pane_title = t('Use view name');
79
    }
80

    
81
    if (drupal_strlen($pane_title) > 16) {
82
      $pane_title = drupal_substr($pane_title, 0, 16) . '...';
83
    }
84

    
85
    $options['pane_title'] = array(
86
      'category' => 'panel_pane',
87
      'title' => t('Admin title'),
88
      'value' => $pane_title,
89
    );
90

    
91
    $pane_description = $this->get_option('pane_description');
92
    if (empty($pane_description)) {
93
      $pane_description = t('Use view description');
94
    }
95

    
96
    if (drupal_strlen($pane_description) > 16) {
97
      $pane_description = drupal_substr($pane_description, 0, 16) . '...';
98
    }
99

    
100
    $options['pane_description'] = array(
101
      'category' => 'panel_pane',
102
      'title' => t('Admin desc'),
103
      'value' => $pane_description,
104
    );
105

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

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

    
116
    $options['pane_category'] = array(
117
      'category' => 'panel_pane',
118
      'title' => t('Category'),
119
      'value' => $pane_category,
120
    );
121

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

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

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

    
140
    $allow = $this->get_option('allow');
141
    $filtered_allow = array_filter($allow);
142

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

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

    
157
    switch ($form_state['section']) {
158
      case 'allow':
159
        $form['#title'] .= t('Allow settings');
160
        $form['description'] = array(
161
          '#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>',
162
        );
163

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

    
176
        $allow = array_filter($this->get_option('allow'));
177
        $form['allow'] = array(
178
          '#type' => 'checkboxes',
179
          '#default_value' => $allow,
180
          '#options' => $options,
181
        );
182
        break;
183

    
184
      case 'pane_title':
185
        $form['#title'] .= t('Administrative title');
186

    
187
        $form['pane_title'] = array(
188
          '#type' => 'textfield',
189
          '#default_value' => $this->get_option('pane_title'),
190
          '#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.'),
191
        );
192
        break;
193

    
194
      case 'pane_description':
195
        $form['#title'] .= t('Administrative description');
196

    
197
        $form['pane_description'] = array(
198
          '#type' => 'textfield',
199
          '#default_value' => $this->get_option('pane_description'),
200
          '#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.'),
201
        );
202
        break;
203

    
204
      case 'pane_category':
205
        $form['#title'] .= t('Administrative description');
206

    
207
        $cat = $this->get_option('pane_category');
208
        $form['pane_category']['#tree'] = TRUE;
209
        $form['pane_category']['name'] = array(
210
          '#type' => 'textfield',
211
          '#default_value' => $cat['name'],
212
          '#description' => t('This is category the pane will appear in on the add content dialog.'),
213
        );
214
        $form['pane_category']['weight'] = array(
215
          '#title' => t('Weight'),
216
          '#type' => 'textfield',
217
          '#default_value' => $cat['weight'],
218
          '#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.'),
219
        );
220
        break;
221

    
222
      case 'link_to_view':
223
        $form['#title'] .= t('Link pane title to view');
224

    
225
        $form['link_to_view'] = array(
226
          '#type' => 'select',
227
          '#options' => array(1 => t('Yes'), 0 => t('No')),
228
          '#default_value' => $this->get_option('link_to_view'),
229
        );
230
        break;
231

    
232
      case 'inherit_panels_path':
233
        $form['#title'] .= t('Inherit path from panel display');
234

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

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

    
250
        $converters = ctools_context_get_all_converters();
251
        ksort($converters);
252

    
253
        foreach ($argument_input as $id => $argument) {
254
          $form['argument_input'][$id] = array(
255
            '#tree' => TRUE,
256
          );
257

    
258
          $safe = str_replace(array('][', '_', ' '), '-', $id);
259
          $type_id = 'edit-argument-input-' . $safe;
260

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

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

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

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

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

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

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

    
351
    // We use a separate output so as to seamlessly discard info for
352
    // arguments that no longer exist.
353
    $output = array();
354

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

    
372
    return $output;
373
  }
374

    
375

    
376
  public function use_more() {
377
    $allow = $this->get_option('allow');
378
    if (!$allow['more_link'] || !$this->has_pane_conf()) {
379
      return parent::use_more();
380
    }
381
    $conf = $this->get_option('pane_conf');
382
    return (bool) $conf['more_link'];
383
  }
384

    
385

    
386
  public function get_path() {
387
    if (empty($this->view->override_path)) {
388
      return parent::get_path();
389
    }
390
    return $this->view->override_path;
391
  }
392

    
393

    
394
  public function get_url() {
395
    if ($this->get_option('inherit_panels_path')) {
396
      return $this->get_path();
397
    }
398
    return parent::get_url();
399
  }
400

    
401

    
402
  public function uses_exposed_form_in_block() {
403
    // We'll always allow the exposed form in a block, regardless of path.
404
    return TRUE;
405
  }
406

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

    
423
}