Projet

Général

Profil

Paste
Télécharger (19 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / includes / plugins.inc @ 4003efde

1
<?php
2

    
3
/**
4
 * @file
5
 * Built in plugins for Views output handling.
6
 */
7

    
8
// @todo Remove this once update.php can use the registry.
9
views_include('base');
10

    
11
/**
12
 * Implements hook_views_plugins().
13
 */
14
function views_views_plugins() {
15
  $js_path = drupal_get_path('module', 'ctools') . '/js';
16
  $plugins = array(
17
    // display, style, row, argument default, argument validator and access.
18
    'display' => array(
19
      // Default settings for all display plugins.
20
      'default' => array(
21
        'title' => t('Master'),
22
        'help' => t('Default settings for this view.'),
23
        'handler' => 'views_plugin_display_default',
24
        'theme' => 'views_view',
25
        'no ui' => TRUE,
26
        'no remove' => TRUE,
27
        'js' => array('misc/form.js', 'misc/collapse.js', 'misc/textarea.js', 'misc/tabledrag.js', 'misc/autocomplete.js', "$js_path/dependent.js"),
28
        'use ajax' => TRUE,
29
        'use pager' => TRUE,
30
        'use more' => TRUE,
31
        'accept attachments' => TRUE,
32
        'help topic' => 'display-default',
33
      ),
34
      'page' => array(
35
        'title' => t('Page'),
36
        'help' => t('Display the view as a page, with a URL and menu links.'),
37
        'handler' => 'views_plugin_display_page',
38
        'theme' => 'views_view',
39
        'uses hook menu' => TRUE,
40
        'contextual links locations' => array('page'),
41
        'use ajax' => TRUE,
42
        'use pager' => TRUE,
43
        'use more' => TRUE,
44
        'accept attachments' => TRUE,
45
        'admin' => t('Page'),
46
        'help topic' => 'display-page',
47
      ),
48
      'block' => array(
49
        'title' => t('Block'),
50
        'help' => t('Display the view as a block.'),
51
        'handler' => 'views_plugin_display_block',
52
        'theme' => 'views_view',
53
        'uses hook block' => TRUE,
54
        'contextual links locations' => array('block'),
55
        'use ajax' => TRUE,
56
        'use pager' => TRUE,
57
        'use more' => TRUE,
58
        'accept attachments' => TRUE,
59
        'admin' => t('Block'),
60
        'help topic' => 'display-block',
61
      ),
62
      'attachment' => array(
63
        'title' => t('Attachment'),
64
        'help' => t('Attachments added to other displays to achieve multiple views in the same view.'),
65
        'handler' => 'views_plugin_display_attachment',
66
        'theme' => 'views_view',
67
        'contextual links locations' => array(),
68
        'use ajax' => TRUE,
69
        'use pager' => FALSE,
70
        'use more' => TRUE,
71
        'accept attachments' => FALSE,
72
        'help topic' => 'display-attachment',
73
      ),
74
      'feed' => array(
75
        'title' => t('Feed'),
76
        'help' => t('Display the view as a feed, such as an RSS feed.'),
77
        'handler' => 'views_plugin_display_feed',
78
        'uses hook menu' => TRUE,
79
        'use ajax' => FALSE,
80
        'use pager' => FALSE,
81
        'accept attachments' => FALSE,
82
        'admin' => t('Feed'),
83
        'help topic' => 'display-feed',
84
      ),
85
      'embed' => array(
86
        'title' => t('Embed'),
87
        'help' => t('Provide a display which can be embedded using the views api.'),
88
        'handler' => 'views_plugin_display_embed',
89
        'theme' => 'views_view',
90
        'uses hook menu' => FALSE,
91
        'use ajax' => TRUE,
92
        'use pager' => TRUE,
93
        'accept attachments' => FALSE,
94
        'admin' => t('Embed'),
95
        'no ui' => !variable_get('views_ui_display_embed', FALSE),
96
      ),
97
    ),
98
    'display_extender' => array(
99
      // Default settings for all display_extender plugins.
100
      'default' => array(
101
        'title' => t('Empty display extender'),
102
        'help' => t('Default settings for this view.'),
103
        'handler' => 'views_plugin_display_extender',
104
        // You can force the plugin to be enabled.
105
        'enabled' => FALSE,
106
        'no ui' => TRUE,
107
      ),
108
    ),
109
    'style' => array(
110
      // Default settings for all style plugins.
111
      'default' => array(
112
        'title' => t('Unformatted list'),
113
        'help' => t('Displays rows one after another.'),
114
        'handler' => 'views_plugin_style_default',
115
        'theme' => 'views_view_unformatted',
116
        'uses row plugin' => TRUE,
117
        'uses row class' => TRUE,
118
        'uses grouping' => TRUE,
119
        'uses options' => TRUE,
120
        'type' => 'normal',
121
        'help topic' => 'style-unformatted',
122
      ),
123
      'list' => array(
124
        'title' => t('HTML list'),
125
        'help' => t('Displays rows as an HTML list.'),
126
        'handler' => 'views_plugin_style_list',
127
        'theme' => 'views_view_list',
128
        'uses row plugin' => TRUE,
129
        'uses row class' => TRUE,
130
        'uses options' => TRUE,
131
        'type' => 'normal',
132
        'help topic' => 'style-list',
133
      ),
134
      'grid' => array(
135
        'title' => t('Grid'),
136
        'help' => t('Displays rows in a grid.'),
137
        'handler' => 'views_plugin_style_grid',
138
        'theme' => 'views_view_grid',
139
        'uses fields' => FALSE,
140
        'uses row plugin' => TRUE,
141
        'uses row class' => TRUE,
142
        'uses options' => TRUE,
143
        'type' => 'normal',
144
        'help topic' => 'style-grid',
145
      ),
146
      'table' => array(
147
        'title' => t('Table'),
148
        'help' => t('Displays rows in a table.'),
149
        'handler' => 'views_plugin_style_table',
150
        'theme' => 'views_view_table',
151
        'uses row plugin' => FALSE,
152
        'uses row class' => TRUE,
153
        'uses fields' => TRUE,
154
        'uses options' => TRUE,
155
        'type' => 'normal',
156
        'help topic' => 'style-table',
157
      ),
158
      'default_summary' => array(
159
        'title' => t('List'),
160
        'help' => t('Displays the default summary as a list.'),
161
        'handler' => 'views_plugin_style_summary',
162
        'theme' => 'views_view_summary',
163
        'type' => 'summary',
164
  // only shows up as a summary style.
165
        'uses options' => TRUE,
166
        'help topic' => 'style-summary',
167
      ),
168
      'unformatted_summary' => array(
169
        'title' => t('Unformatted'),
170
        'help' => t('Displays the summary unformatted, with option for one after another or inline.'),
171
        'handler' => 'views_plugin_style_summary_unformatted',
172
        'theme' => 'views_view_summary_unformatted',
173
        'type' => 'summary',
174
  // only shows up as a summary style.
175
        'uses options' => TRUE,
176
        'help topic' => 'style-summary-unformatted',
177
      ),
178
      'rss' => array(
179
        'title' => t('RSS Feed'),
180
        'help' => t('Generates an RSS feed from a view.'),
181
        'handler' => 'views_plugin_style_rss',
182
        'theme' => 'views_view_rss',
183
        'uses row plugin' => TRUE,
184
        'uses options' => TRUE,
185
        'type' => 'feed',
186
        'help topic' => 'style-rss',
187
      ),
188
    ),
189
    'row' => array(
190
      'fields' => array(
191
        'title' => t('Fields'),
192
        'help' => t('Displays the fields with an optional template.'),
193
        'handler' => 'views_plugin_row_fields',
194
        'theme' => 'views_view_fields',
195
        'uses fields' => TRUE,
196
        'uses options' => TRUE,
197
        'type' => 'normal',
198
        'help topic' => 'style-row-fields',
199
      ),
200
      'rss_fields' => array(
201
        'title' => t('Fields'),
202
        'help' => t('Display fields as RSS items.'),
203
        'handler' => 'views_plugin_row_rss_fields',
204
        'theme' => 'views_view_row_rss',
205
        'uses fields' => TRUE,
206
        'uses options' => TRUE,
207
        'type' => 'feed',
208
        'help topic' => 'style-row-fields',
209
      ),
210
    ),
211
    'argument default' => array(
212
      'parent' => array(
213
        'no ui' => TRUE,
214
        'handler' => 'views_plugin_argument_default',
215
        'parent' => '',
216
      ),
217
      'fixed' => array(
218
        'title' => t('Fixed value'),
219
        'handler' => 'views_plugin_argument_default_fixed',
220
      ),
221
      'php' => array(
222
        'title' => t('PHP Code'),
223
        'handler' => 'views_plugin_argument_default_php',
224
      ),
225
      'raw' => array(
226
        'title' => t('Raw value from URL'),
227
        'handler' => 'views_plugin_argument_default_raw',
228
      ),
229
    ),
230
    'argument validator' => array(
231
      'php' => array(
232
        'title' => t('PHP Code'),
233
        'handler' => 'views_plugin_argument_validate_php',
234
      ),
235
      'numeric' => array(
236
        'title' => t('Numeric'),
237
        'handler' => 'views_plugin_argument_validate_numeric',
238
      ),
239
    ),
240
    'access' => array(
241
      'none' => array(
242
        'title' => t('None'),
243
        'help' => t('Will be available to all users.'),
244
        'handler' => 'views_plugin_access_none',
245
        'help topic' => 'access-none',
246
      ),
247
      'role' => array(
248
        'title' => t('Role'),
249
        'help' => t('Access will be granted to users with any of the specified roles.'),
250
        'handler' => 'views_plugin_access_role',
251
        'uses options' => TRUE,
252
        'help topic' => 'access-role',
253
      ),
254
      'perm' => array(
255
        'title' => t('Permission'),
256
        'help' => t('Access will be granted to users with the specified permission string.'),
257
        'handler' => 'views_plugin_access_perm',
258
        'uses options' => TRUE,
259
        'help topic' => 'access-perm',
260
      ),
261
    ),
262
    'query' => array(
263
      'parent' => array(
264
        'no ui' => TRUE,
265
        'handler' => 'views_plugin_query',
266
        'parent' => '',
267
      ),
268
      'views_query' => array(
269
        'title' => t('SQL Query'),
270
        'help' => t('Query will be generated and run using the Drupal database API.'),
271
        'handler' => 'views_plugin_query_default',
272
      ),
273
    ),
274
    'cache' => array(
275
      'parent' => array(
276
        'no ui' => TRUE,
277
        'handler' => 'views_plugin_cache',
278
        'parent' => '',
279
      ),
280
      'none' => array(
281
        'title' => t('None'),
282
        'help' => t('No caching of Views data.'),
283
        'handler' => 'views_plugin_cache_none',
284
        'help topic' => 'cache-none',
285
      ),
286
      'time' => array(
287
        'title' => t('Time-based'),
288
        'help' => t('Simple time-based caching of data.'),
289
        'handler' => 'views_plugin_cache_time',
290
        'uses options' => TRUE,
291
        'help topic' => 'cache-time',
292
      ),
293
    ),
294
    'exposed_form' => array(
295
      'parent' => array(
296
        'no ui' => TRUE,
297
        'handler' => 'views_plugin_exposed_form',
298
        'parent' => '',
299
      ),
300
      'basic' => array(
301
        'title' => t('Basic'),
302
        'help' => t('Basic exposed form'),
303
        'handler' => 'views_plugin_exposed_form_basic',
304
        'uses options' => TRUE,
305
        'help topic' => 'exposed-form-basic',
306
      ),
307
      'input_required' => array(
308
        'title' => t('Input required'),
309
        'help' => t('An exposed form that only renders a view if the form contains user input.'),
310
        'handler' => 'views_plugin_exposed_form_input_required',
311
        'uses options' => TRUE,
312
        'help topic' => 'exposed-form-input-required',
313
      ),
314
    ),
315
    'pager' => array(
316
      'parent' => array(
317
        'no ui' => TRUE,
318
        'handler' => 'views_plugin_pager',
319
        'parent' => '',
320
      ),
321
      'none' => array(
322
        'title' => t('Display all items'),
323
        'help' => t("Display all items that this view might find"),
324
        'handler' => 'views_plugin_pager_none',
325
        'help topic' => 'pager-none',
326
        'uses options' => TRUE,
327
        'type' => 'basic',
328
      ),
329
      'some' => array(
330
        'title' => t('Display a specified number of items'),
331
        'help' => t('Display a limited number items that this view might find.'),
332
        'handler' => 'views_plugin_pager_some',
333
        'help topic' => 'pager-some',
334
        'uses options' => TRUE,
335
        'type' => 'basic',
336
      ),
337
      'full' => array(
338
        'title' => t('Paged output, full pager'),
339
        'short title' => t('Full'),
340
        'help' => t('Paged output, full Drupal style'),
341
        'handler' => 'views_plugin_pager_full',
342
        'help topic' => 'pager-full',
343
        'uses options' => TRUE,
344
      ),
345
      'mini' => array(
346
        'title' => t('Paged output, mini pager'),
347
        'short title' => t('Mini'),
348
        'help' => t('Use the mini pager output.'),
349
        'handler' => 'views_plugin_pager_mini',
350
        'help topic' => 'pager-mini',
351
        'uses options' => TRUE,
352
        'parent' => 'full',
353
      ),
354
    ),
355
    'localization' => array(
356
      'parent' => array(
357
        'no ui' => TRUE,
358
        'handler' => 'views_plugin_localization',
359
        'parent' => '',
360
      ),
361
      'none' => array(
362
        'title' => t('None'),
363
        'help' => t('Do not pass admin strings for translation.'),
364
        'handler' => 'views_plugin_localization_none',
365
        'help topic' => 'localization-none',
366
      ),
367
      'core' => array(
368
        'title' => t('Core'),
369
        'help' => t("Use Drupal core t() function. Not recommended, as it doesn't support updates to existing strings."),
370
        'handler' => 'views_plugin_localization_core',
371
        'help topic' => 'localization-core',
372
      ),
373
    ),
374
  );
375
  // Add a help message pointing to the i18views module if it is not present.
376
  if (!module_exists('i18nviews')) {
377
    $plugins['localization']['core']['help'] .= ' ' . t('If you need to translate Views labels into other languages, consider installing the <a href="!path">Internationalization</a> package\'s Views translation module.', array('!path' => url('http://drupal.org/project/i18n', array('absolute' => TRUE))));
378
  }
379

    
380
  if (module_invoke('ctools', 'api_version', '1.3')) {
381
    $plugins['style']['jump_menu_summary'] = array(
382
      'title' => t('Jump menu'),
383
      'help' => t('Puts all of the results into a select box and allows the user to go to a different page based upon the results.'),
384
      'handler' => 'views_plugin_style_summary_jump_menu',
385
      'theme' => 'views_view_summary_jump_menu',
386
      'type' => 'summary',
387
    // only shows up as a summary style.
388
      'uses options' => TRUE,
389
      'help topic' => 'style-summary-jump-menu',
390
    );
391
    $plugins['style']['jump_menu'] = array(
392
      'title' => t('Jump menu'),
393
      'help' => t('Puts all of the results into a select box and allows the user to go to a different page based upon the results.'),
394
      'handler' => 'views_plugin_style_jump_menu',
395
      'theme' => 'views_view_jump_menu',
396
      'uses row plugin' => TRUE,
397
      'uses fields' => TRUE,
398
      'uses options' => TRUE,
399
      'type' => 'normal',
400
      'help topic' => 'style-jump-menu',
401
    );
402
  }
403

    
404
  return $plugins;
405
}
406

    
407
/**
408
 * Builds and return a list of all plugins available in the system.
409
 *
410
 * @return Nested array of plugins, grouped by type.
411
 */
412
function views_discover_plugins() {
413
  $cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array(), 'cache' => array(), 'exposed_form' => array());
414
  // Get plugins from all modules.
415
  foreach (module_implements('views_plugins') as $module) {
416
    $function = $module . '_views_plugins';
417
    $result = $function();
418
    if (!is_array($result)) {
419
      continue;
420
    }
421

    
422
    $module_dir = isset($result['module']) ? $result['module'] : $module;
423
    // Setup automatic path/file finding for theme registration.
424
    if ($module_dir == 'views') {
425
      $theme_path = drupal_get_path('module', $module_dir) . '/theme';
426
      $theme_file = 'theme.inc';
427
      $path = drupal_get_path('module', $module_dir) . '/plugins';
428
    }
429
    else {
430
      $theme_path = $path = drupal_get_path('module', $module_dir);
431
      $theme_file = "$module.views.inc";
432
    }
433

    
434
    foreach ($result as $type => $info) {
435
      if ($type == 'module') {
436
        continue;
437
      }
438
      foreach ($info as $plugin => $def) {
439
        $def['module'] = $module_dir;
440
        if (!isset($def['theme path'])) {
441
          $def['theme path'] = $theme_path;
442
        }
443
        if (!isset($def['theme file'])) {
444
          $def['theme file'] = $theme_file;
445
        }
446
        if (!isset($def['path'])) {
447
          $def['path'] = $path;
448
        }
449
        if (!isset($def['file'])) {
450
          $def['file'] = $def['handler'] . '.inc';
451
        }
452
        if (!isset($def['parent'])) {
453
          $def['parent'] = 'parent';
454
        }
455
        // Set the internal name to be able to read it out later.
456
        $def['name'] = $plugin;
457

    
458
        // merge the new data in.
459
        $cache[$type][$plugin] = $def;
460
      }
461
    }
462
  }
463

    
464
  // Let other modules modify the plugins.
465
  drupal_alter('views_plugins', $cache);
466
  return $cache;
467
}
468

    
469
/**
470
 * Abstract base class to provide interface common to all plugins.
471
 */
472
class views_plugin extends views_object {
473

    
474
  /**
475
   * The top object of a view.
476
   *
477
   * @var view
478
   */
479
  public $view = NULL;
480

    
481
  /**
482
   * The current used views display.
483
   *
484
   * @var views_display
485
   */
486
  public $display = NULL;
487

    
488
  /**
489
   * The plugin type of this plugin, for example style or query.
490
   */
491
  public $plugin_type = NULL;
492

    
493
  /**
494
   * The plugin name of this plugin, for example table or full.
495
   */
496
  public $plugin_name = NULL;
497

    
498
  /**
499
   * Init will be called after construct, when the plugin is attached to a
500
   * view and a display.
501
   */
502

    
503
  /**
504
   * Provide a form to edit options for this plugin.
505
   */
506
  public function options_form(&$form, &$form_state) {
507
    // Some form elements belong in a fieldset for presentation, but can't
508
    // be moved into one because of the form_state['values'] hierarchy. Those
509
    // elements can add a #fieldset => 'fieldset_name' property, and they'll
510
    // be moved to their fieldset during pre_render.
511
    $form['#pre_render'][] = 'views_ui_pre_render_add_fieldset_markup';
512
  }
513

    
514
  /**
515
   * Validate the options form.
516
   */
517
  public function options_validate(&$form, &$form_state) {
518
  }
519

    
520
  /**
521
   * Handle any special handling on the validate form.
522
   */
523
  public function options_submit(&$form, &$form_state) {
524
  }
525

    
526
  /**
527
   * Add anything to the query that we might need to.
528
   */
529
  public function query() {
530
  }
531

    
532
  /**
533
   * Provide a full list of possible theme templates used by this style.
534
   */
535
  public function theme_functions() {
536
    if (empty($this->definition['theme'])) {
537
      $this->definition['theme'] = 'views_view';
538
    }
539
    return views_theme_functions($this->definition['theme'], $this->view, $this->display);
540
  }
541

    
542
  /**
543
   * Provide a list of additional theme functions for the theme info page.
544
   */
545
  public function additional_theme_functions() {
546
    $funcs = array();
547
    if (!empty($this->definition['additional themes'])) {
548
      foreach ($this->definition['additional themes'] as $theme => $type) {
549
        $funcs[] = views_theme_functions($theme, $this->view, $this->display);
550
      }
551
    }
552
    return $funcs;
553
  }
554

    
555
  /**
556
   * Validate that the plugin is correct and can be saved.
557
   *
558
   * @return array
559
   *   An array of error strings to tell the user what is wrong with this
560
   *   plugin.
561
   */
562
  public function validate() {
563
    return array();
564
  }
565

    
566
  /**
567
   * Returns the summary of the settings in the display.
568
   */
569
  public function summary_title() {
570
    return t('Settings');
571
  }
572
  /**
573
   * Return the human readable name of the display.
574
   *
575
   * This appears on the ui beside each plugin and beside the settings link.
576
   */
577
  public function plugin_title() {
578
    if (isset($this->definition['short title'])) {
579
      return check_plain($this->definition['short title']);
580
    }
581
    return check_plain($this->definition['title']);
582
  }
583

    
584
}
585

    
586
/**
587
 * Get enabled display extenders.
588
 */
589
function views_get_enabled_display_extenders() {
590
  $enabled = array_filter(variable_get('views_display_extenders', array()));
591
  $options = views_fetch_plugin_names('display_extender');
592
  foreach ($options as $name => $plugin) {
593
    $enabled[$name] = $name;
594
  }
595

    
596
  return $enabled;
597
}