/[drupal]/contributions/modules/views/plugins/views_plugin_display.inc
ViewVC logotype

Contents of /contributions/modules/views/plugins/views_plugin_display.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.27 - (show annotations) (download) (as text)
Mon Sep 21 21:26:56 2009 UTC (2 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.26: +3 -3 lines
File MIME type: text/x-php
#563564 by dereine: Unformatted style does not use options, so the options icon should not appear.
1 <?php
2 // $Id: views_plugin_display.inc,v 1.26 2009/09/15 21:54:23 merlinofchaos Exp $
3 /**
4 * @file
5 * Contains the base display plugin.
6 */
7
8 /**
9 * @defgroup views_display_plugins Views' display plugins
10 * @{
11 * Display plugins control how Views interact with the rest of Drupal.
12 *
13 * They can handle creating Views from a Drupal page hook; they can
14 * handle creating Views from a Drupal block hook. They can also
15 * handle creating Views from an external module source, such as
16 * a Panels pane, or an insert view, or a CCK field type.
17 *
18 * @see hook_views_plugins
19 */
20
21 /**
22 * The default display plugin handler. Display plugins handle options and
23 * basic mechanisms for different output methods.
24 *
25 * @ingroup views_display_plugins
26 */
27 class views_plugin_display extends views_plugin {
28 var $handlers = array();
29
30 function init(&$view, &$display, $options = NULL) {
31 $this->view = &$view;
32 $this->display = &$display;
33
34 // Make some modifications:
35 if (!isset($options)) {
36 $options = $display->display_options;
37 }
38
39 if ($this->is_default_display() && isset($options['defaults'])) {
40 unset($options['defaults']);
41 }
42
43 $this->unpack_options($this->options, $options);
44 }
45
46 function destroy() {
47 parent::destroy();
48
49 foreach ($this->handlers as $type => $handlers) {
50 foreach ($handlers as $id => $handler) {
51 if (is_object($handler)) {
52 $this->handlers[$type][$id]->destroy();
53 }
54 }
55 }
56
57 if (isset($this->default_display)) {
58 unset($this->default_display);
59 }
60 }
61
62 /**
63 * Determine if this display is the 'default' display which contains
64 * fallback settings
65 */
66 function is_default_display() { return FALSE; }
67
68 /**
69 * Determine if this display uses exposed filters, so the view
70 * will know whether or not to build them.
71 */
72 function uses_exposed() {
73 if (!isset($this->has_exposed)) {
74 foreach (array('field', 'filter') as $type) {
75 foreach ($this->view->$type as $key => $handler) {
76 if ($handler->is_exposed()) {
77 // one is all we need; if we find it, return true.
78 $this->has_exposed = TRUE;
79 return TRUE;
80 }
81 }
82 }
83 $this->has_exposed = FALSE;
84 }
85
86 return $this->has_exposed;
87 }
88
89 /**
90 * Determine if this display should display the exposed
91 * filters widgets, so the view will know whether or not
92 * to render them.
93 *
94 * Regardless of what this function
95 * returns, exposed filters will not be used nor
96 * displayed unless uses_exposed() returns TRUE.
97 */
98 function displays_exposed() {
99 return TRUE;
100 }
101
102 /**
103 * Does the display use AJAX?
104 */
105 function use_ajax() {
106 if (!empty($this->definition['use ajax'])) {
107 return $this->get_option('use_ajax');
108 }
109 return FALSE;
110 }
111
112 /**
113 * Does the display have a pager enabled?
114 */
115 function use_pager() {
116 if (!empty($this->definition['use pager'])) {
117 return $this->get_option('use_pager');
118 }
119 return FALSE;
120 }
121
122 /**
123 * Does the display have a more link enabled?
124 */
125 function use_more() {
126 if (!empty($this->definition['use more'])) {
127 return $this->get_option('use_more');
128 }
129 return FALSE;
130 }
131
132 /**
133 * Does the display have custom link text?
134 */
135 function use_more_text() {
136 if (!empty($this->definition['use more'])) {
137 return $this->get_option('use_more_text');
138 }
139 return FALSE;
140 }
141
142 /**
143 * Can this display accept attachments?
144 */
145 function accept_attachments() {
146 return !empty($this->definition['accept attachments']);
147 }
148
149 /**
150 * Allow displays to attach to other views.
151 */
152 function attach_to($display_id) { }
153
154 /**
155 * Static member function to list which sections are defaultable
156 * and what items each section contains.
157 */
158 function defaultable_sections($section = NULL) {
159 $sections = array(
160 'access' => array('access'),
161 'cache' => array('cache'),
162 'title' => array('title'),
163 'header' => array('header', 'header_format', 'header_empty'),
164 'footer' => array('footer', 'footer_format', 'footer_empty'),
165 'empty' => array('empty', 'empty_format'),
166 'use_ajax' => array('use_ajax'),
167 'items_per_page' => array('items_per_page', 'offset', 'use_pager', 'pager_element'),
168 'use_pager' => array('items_per_page', 'offset', 'use_pager', 'pager_element'),
169 'use_more' => array('use_more', 'use_more_text'),
170 'link_display' => array('link_display'),
171 'distinct' => array('distinct'),
172 'exposed_block' => array('exposed_block'),
173
174 // Force these to cascade properly.
175 'style_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
176 'style_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
177 'row_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
178 'row_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
179
180 // These guys are special
181 'relationships' => array('relationships'),
182 'fields' => array('fields'),
183 'sorts' => array('sorts'),
184 'arguments' => array('arguments'),
185 'filters' => array('filters'),
186 );
187 if ($section) {
188 if (!empty($sections[$section])) {
189 return $sections[$section];
190 }
191 }
192 else {
193 return $sections;
194 }
195 }
196
197 /**
198 * Set default options.
199 *
200 * Displays put their options in a different place than everything else; also
201 * displays spread their options out. We don't want to set defaults for
202 * items that are normally defaulted elsewhere.
203 */
204 function _set_option_defaults(&$storage, $options, $level = 0) {
205 foreach ($options as $option => $definition) {
206 // If defaulted to elsewhere and we're not the default display, skip.
207 if ($level == 0 && !$this->is_default_display() && !empty($options['defaults']['default'][$option])) {
208 continue;
209 }
210
211 if (isset($definition['contains']) && is_array($definition['contains'])) {
212 $storage[$option] = array();
213 $this->_set_option_defaults($storage[$option], $definition['contains'], $level++);
214 }
215 else {
216 $storage[$option] = isset($definition['default']) ? $definition['default'] : NULL;
217 }
218 }
219 }
220
221 function option_definition() {
222 $options = array(
223 'defaults' => array(
224 'default' => array(
225 'access' => TRUE,
226 'cache' => TRUE,
227 'title' => TRUE,
228 'header' => TRUE,
229 'header_format' => TRUE,
230 'header_empty' => TRUE,
231 'footer' => TRUE,
232 'footer_format' => TRUE,
233 'footer_empty' => TRUE,
234 'empty' => TRUE,
235 'empty_format' => TRUE,
236
237 'use_ajax' => TRUE,
238 'items_per_page' => TRUE,
239 'offset' => TRUE,
240 'use_pager' => TRUE,
241 'pager_element' => TRUE,
242 'use_more' => TRUE,
243 'use_more_text' => TRUE,
244 'distinct' => TRUE,
245 'exposed_block' => TRUE,
246
247 'link_display' => TRUE,
248
249 'style_plugin' => TRUE,
250 'style_options' => TRUE,
251 'row_plugin' => TRUE,
252 'row_options' => TRUE,
253
254 'relationships' => TRUE,
255 'fields' => TRUE,
256 'sorts' => TRUE,
257 'arguments' => TRUE,
258 'filters' => TRUE,
259 ),
260 ),
261 'relationships' => array(
262 'default' => array(),
263 'export' => 'export_item',
264 ),
265 'fields' => array(
266 'default' => array(),
267 'export' => 'export_item',
268 ),
269 'sorts' => array(
270 'default' => array(),
271 'export' => 'export_item',
272 ),
273 'arguments' => array(
274 'default' => array(),
275 'export' => 'export_item',
276 ),
277 'filters' => array(
278 'default' => array(),
279 'export' => 'export_item',
280 ),
281 'access' => array(
282 'contains' => array(
283 'type' => array('default' => 'none'),
284 ),
285 ),
286 'cache' => array(
287 'contains' => array(
288 'type' => array('default' => 'none'),
289 ),
290 ),
291 'title' => array(
292 'default' => '',
293 'translatable' => TRUE,
294 ),
295 'header' => array(
296 'default' => '',
297 'translatable' => TRUE,
298 ),
299 'header_format' => array(
300 'default' => FILTER_FORMAT_DEFAULT,
301 ),
302 'header_empty' => array(
303 'default' => FALSE,
304 ),
305 'footer' => array(
306 'default' => '',
307 'translatable' => TRUE,
308 ),
309 'footer_format' => array(
310 'default' => FILTER_FORMAT_DEFAULT,
311 ),
312 'footer_empty' => array(
313 'default' => FALSE,
314 ),
315 'empty' => array(
316 'default' => '',
317 'translatable' => TRUE,
318 ),
319 'empty_format' => array(
320 'default' => FILTER_FORMAT_DEFAULT,
321 ),
322 'use_ajax' => array(
323 'default' => FALSE,
324 ),
325 'items_per_page' => array(
326 'default' => 10,
327 ),
328 'offset' => array(
329 'default' => 0,
330 ),
331 'use_pager' => array(
332 'default' => FALSE,
333 ),
334 'pager_element' => array(
335 'default' => 0,
336 ),
337 'use_more' => array(
338 'default' => FALSE,
339 ),
340 'use_more_text' => array(
341 'default' => 'more',
342 'translatable' => TRUE,
343 ),
344 'link_display' => array(
345 'default' => '',
346 ),
347 'distinct' => array(
348 'default' => FALSE,
349 ),
350
351 'style_plugin' => array(
352 'default' => 'default',
353 ),
354 'style_options' => array(
355 'default' => array(),
356 ),
357 'row_plugin' => array(
358 'default' => 'fields',
359 ),
360 'row_options' => array(
361 'default' => array(),
362 ),
363
364 'exposed_block' => array(
365 'default' => FALSE,
366 ),
367 );
368
369 if ($this->is_default_display()) {
370 unset($options['defaults']);
371 }
372 return $options;
373 }
374
375 /**
376 * Check to see if the display has a 'path' field.
377 *
378 * This is a pure function and not just a setting on the definition
379 * because some displays (such as a panel pane) may have a path based
380 * upon configuration.
381 *
382 * By default, displays do not have a path.
383 */
384 function has_path() { return FALSE; }
385
386 /**
387 * Check to see if the display has some need to link to another display.
388 *
389 * For the most part, displays without a path will use a link display. However,
390 * sometimes displays that have a path might also need to link to another display.
391 * This is true for feeds.
392 */
393 function uses_link_display() { return !$this->has_path(); }
394
395 /**
396 * Check to see which display to use when creating links within
397 * a view using this display.
398 */
399 function get_link_display() {
400 $display_id = $this->get_option('link_display');
401 // If unknown, pick the first one.
402 if (empty($display_id) || empty($this->view->display[$display_id])) {
403 foreach ($this->view->display as $display_id => $display) {
404 if (!empty($display->handler) && $display->handler->has_path()) {
405 return $display_id;
406 }
407 }
408 }
409 else {
410 return $display_id;
411 }
412 // fall-through returns NULL
413 }
414
415 /**
416 * Return the base path to use for this display.
417 *
418 * This can be overridden for displays that do strange things
419 * with the path.
420 */
421 function get_path() {
422 if ($this->has_path()) {
423 return $this->get_option('path');
424 }
425
426 $display_id = $this->get_link_display();
427 if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
428 return $this->view->display[$display_id]->handler->get_path();
429 }
430 }
431
432 /**
433 * Check to see if the display needs a breadcrumb
434 *
435 * By default, displays do not need breadcrumbs
436 */
437 function uses_breadcrumb() { return FALSE; }
438
439 /**
440 * Determine if a given option is set to use the default display or the
441 * current display
442 *
443 * @return
444 * TRUE for the default display
445 */
446 function is_defaulted($option) {
447 return !$this->is_default_display() && !empty($this->default_display) && !empty($this->options['defaults'][$option]);
448 }
449
450 /**
451 * Intelligently get an option either from this display or from the
452 * default display, if directed to do so.
453 */
454 function get_option($option) {
455 if ($this->is_defaulted($option)) {
456 return $this->default_display->get_option($option);
457 }
458
459 if (array_key_exists($option, $this->options)) {
460 return $this->options[$option];
461 }
462 }
463
464 /**
465 * Determine if the display's style uses fields.
466 */
467 function uses_fields() {
468 $plugin = $this->get_plugin();
469 if ($plugin) {
470 return $plugin->uses_fields();
471 }
472 }
473
474 /**
475 * Get the display or row plugin, if it exists.
476 */
477 function get_plugin($type = 'style', $name = NULL) {
478 if (!$name) {
479 $name = $this->get_option($type . '_plugin');
480 }
481
482 $plugin = views_get_plugin($type, $name);
483 if ($plugin) {
484 $options = $this->get_option($type . '_options');
485 $plugin->init($this->view, $this->display, $options);
486 return $plugin;
487 }
488 }
489
490 /**
491 * Get the access plugin
492 */
493 function get_access_plugin($name = NULL) {
494 if (!$name) {
495 $access = $this->get_option('access');
496 $name = $access['type'];
497 }
498
499 $plugin = views_get_plugin('access', $name);
500 if ($plugin) {
501 $plugin->init($this->view, $this->display);
502 return $plugin;
503 }
504 }
505
506 /**
507 * Get the cache plugin
508 */
509 function get_cache_plugin($name = NULL) {
510 if (!$name) {
511 $cache = $this->get_option('cache');
512 $name = $cache['type'];
513 }
514
515 $plugin = views_get_plugin('cache', $name);
516 if ($plugin) {
517 $plugin->init($this->view, $this->display);
518 return $plugin;
519 }
520 }
521
522 /**
523 * Get the handler object for a single handler.
524 */
525 function &get_handler($type, $id) {
526 if (!isset($this->handlers[$type])) {
527 $this->get_handlers($type);
528 }
529
530 if (isset($this->handlers[$type][$id])) {
531 return $this->handlers[$type][$id];
532 }
533
534 // So we can return a reference.
535 $null = NULL;
536 return $null;
537 }
538
539 /**
540 * Get a full array of handlers for $type. This caches them.
541 */
542 function get_handlers($type) {
543 if (!isset($this->handlers[$type])) {
544 $this->handlers[$type] = array();
545 $types = views_object_types();
546 $plural = $types[$type]['plural'];
547 foreach ($this->get_option($plural) as $id => $info) {
548 $handler = views_get_handler($info['table'], $info['field'], $type);
549 if ($handler) {
550 $handler->init($this->view, $info);
551 $this->handlers[$type][$id] = &$handler;
552 }
553
554 // Prevent reference problems.
555 unset($handler);
556 }
557 }
558
559 return $this->handlers[$type];
560 }
561
562 /**
563 * Intelligently set an option either from this display or from the
564 * default display, if directed to do so.
565 */
566 function set_option($option, $value) {
567 if ($this->is_defaulted($option)) {
568 return $this->default_display->set_option($option, $value);
569 }
570
571 // Set this in two places: On the handler where we'll notice it
572 // but also on the display object so it gets saved. This should
573 // only be a temporary fix.
574 $this->display->display_options[$option] = $value;
575 return $this->options[$option] = $value;
576 }
577
578 /**
579 * Set an option and force it to be an override.
580 */
581 function override_option($option, $value) {
582 $this->set_override($option, FALSE);
583 $this->set_option($option, $value);
584 }
585
586 /**
587 * Because forms may be split up into sections, this provides
588 * an easy URL to exactly the right section. Don't override this.
589 */
590 function option_link($text, $section, $class = '', $title = '') {
591 if (!empty($class)) {
592 $text = '<span>' . $text . '</span>';
593 }
594
595 if (!trim($text)) {
596 $text = t('Broken field');
597 }
598
599 if (empty($title)) {
600 $title = $text;
601 }
602
603 return l($text, 'admin/build/views/nojs/display/' . $this->view->name . '/' . $this->display->id . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title), 'html' => TRUE));
604 }
605
606 /**
607 * Provide the default summary for options in the views UI.
608 *
609 * This output is returned as an array.
610 */
611 function options_summary(&$categories, &$options) {
612 $categories['basic'] = array(
613 'title' => t('Basic settings'),
614 );
615
616 $options['display_title'] = array(
617 'category' => 'basic',
618 'title' => t('Name'),
619 'value' => check_plain($this->display->display_title),
620 'desc' => t('Change the name of this display.'),
621 );
622
623 $title = strip_tags($this->get_option('title'));
624 if (!$title) {
625 $title = t('None');
626 }
627
628 $options['title'] = array(
629 'category' => 'basic',
630 'title' => t('Title'),
631 'value' => $title,
632 'desc' => t('Change the title that this display will use.'),
633 );
634
635 $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin'));
636 $style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin['title'];
637
638 $style = '';
639
640 $options['style_plugin'] = array(
641 'category' => 'basic',
642 'title' => t('Style'),
643 'value' => $style_title,
644 'desc' => t('Change the style plugin.'),
645 );
646
647 // This adds a 'Settings' link to the style_options setting if the style has options.
648 if (!empty($style_plugin['uses options'])) {
649 $options['style_plugin']['links']['style_options'] = t('Change settings for this style');
650 }
651
652 if (!empty($style_plugin['uses row plugin'])) {
653 $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
654 $row_title = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin['title'];
655
656 $options['row_plugin'] = array(
657 'category' => 'basic',
658 'title' => t('Row style'),
659 'value' => $row_title,
660 'desc' => t('Change the row plugin.'),
661 );
662 // This adds a 'Settings' link to the row_options setting if the row style has options.
663 if (!empty($row_plugin['uses options'])) {
664 $options['row_plugin']['links']['row_options'] = t('Change settings for this style');
665 }
666 }
667 if (!empty($this->definition['use ajax'])) {
668 $options['use_ajax'] = array(
669 'category' => 'basic',
670 'title' => t('Use AJAX'),
671 'value' => $this->get_option('use_ajax') ? t('Yes') : t('No'),
672 'desc' => t('Change whether or not this display will use AJAX.'),
673 );
674 }
675
676 if (!empty($this->definition['use pager'])) {
677 $options['use_pager'] = array(
678 'category' => 'basic',
679 'title' => t('Use pager'),
680 'value' => $this->get_option('use_pager') ? ($this->get_option('use_pager') === 'mini' ? t('Mini') : t('Yes')) : t('No'),
681 'desc' => t("Change this display's pager setting."),
682 );
683 }
684
685 $items = intval($this->get_option('items_per_page'));
686 $options['items_per_page'] = array(
687 'category' => 'basic',
688 'title' => $this->use_pager() ? t('Items per page') : t('Items to display'),
689 'value' => $items ? $items : t('Unlimited'),
690 'desc' => t('Change how many items to display.'),
691 );
692
693 if (!empty($this->definition['use more'])) {
694 $options['use_more'] = array(
695 'category' => 'basic',
696 'title' => t('More link'),
697 'value' => $this->get_option('use_more') ? t('Yes') : t('No'),
698 'desc' => t('Specify whether this display will provide a "more" link.'),
699 );
700 }
701
702 $options['distinct'] = array(
703 'category' => 'basic',
704 'title' => t('Distinct'),
705 'value' => $this->get_option('distinct') ? t('Yes') : t('No'),
706 'desc' => t('Display only distinct items, without duplicates.'),
707 );
708
709 $access_plugin = $this->get_access_plugin();
710 if (!$access_plugin) {
711 // default to the no access control plugin.
712 $access_plugin = views_get_plugin('access', 'none');
713 }
714
715 $access_str = $access_plugin->summary_title();
716
717 $options['access'] = array(
718 'category' => 'basic',
719 'title' => t('Access'),
720 'value' => $access_str,
721 'desc' => t('Specify access control type for this display.'),
722 );
723
724 if (!empty($access_plugin->definition['uses options'])) {
725 $options['access']['links']['access_options'] = t('Change settings for this access type.');
726 }
727
728 $cache_plugin = $this->get_cache_plugin();
729 if (!$cache_plugin) {
730 // default to the no cache control plugin.
731 $cache_plugin = views_get_plugin('cache', 'none');
732 }
733
734 $cache_str = $cache_plugin->summary_title();
735
736 $options['cache'] = array(
737 'category' => 'basic',
738 'title' => t('Caching'),
739 'value' => $cache_str,
740 'desc' => t('Specify caching type for this display.'),
741 );
742
743 if (!empty($cache_plugin->definition['uses options'])) {
744 $options['cache']['links']['cache_options'] = t('Change settings for this caching type.');
745 }
746
747 if ($this->uses_link_display()) {
748 // Only show the 'link display' if there is more than one option.
749 $count = 0;
750 foreach ($this->view->display as $display_id => $display) {
751 if (is_object($display->handler) && $display->handler->has_path()) {
752 $count++;
753 }
754 if ($count > 1) {
755 break;
756 }
757 }
758
759 if ($count > 1) {
760 $display_id = $this->get_link_display();
761 $link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]->display_title);
762 $options['link_display'] = array(
763 'category' => 'basic',
764 'title' => t('Link display'),
765 'value' => $link_display,
766 'desc' => t('Specify which display this display will link to.'),
767 );
768 }
769 }
770
771 $options['exposed_block'] = array(
772 'category' => 'basic',
773 'title' => t('Exposed form in block'),
774 'value' => $this->get_option('exposed_block') ? t('Yes') : t('No'),
775 'desc' => t('Allow the exposed form to appear in a block instead of the view.'),
776 );
777
778 foreach (array('header' => t('Header'), 'footer' => t('Footer'), 'empty' => t('Empty text')) as $type => $name) {
779 if (!$this->get_option($type)) {
780 $field = t('None');
781 }
782 else {
783 // A lot of code to get the name of the filter format.
784 $fmt_string = $this->get_option($type . '_format');
785 if (empty($fmt_string)) {
786 $fmt_string = FILTER_FORMAT_DEFAULT;
787 }
788 $format_val = filter_resolve_format($fmt_string);
789 $format = filter_formats($format_val);
790 if ($format) {
791 $field = check_plain($format->name);
792 }
793 else {
794 $field = t('Unknown/missing format');
795 }
796 }
797
798 $options[$type] = array(
799 'category' => 'basic',
800 'title' => $name,
801 'value' => $field,
802 'desc' => t("Change this display's !name.", array('!name' => strtolower($name))),
803 );
804 }
805
806 $options['analyze-theme'] = array(
807 'category' => 'basic',
808 'title' => t('Theme'),
809 'value' => t('Information'),
810 'desc' => t('Get information on how to theme this display'),
811 );
812 }
813
814 /**
815 * Provide the default form for setting options.
816 */
817 function options_form(&$form, &$form_state) {
818 if ($this->defaultable_sections($form_state['section'])) {
819 $this->add_override_button($form, $form_state, $form_state['section']);
820 }
821 $form['#title'] = check_plain($this->display->display_title) . ': ';
822
823 // Set the 'section' to hilite on the form.
824 // If it's the item we're looking at is pulling from the default display,
825 // reflect that. Don't use is_defaulted since we want it to show up even
826 // on the default display.
827 if (!empty($this->options['defaults'][$form_state['section']])) {
828 $form['#section'] = 'default-' . $form_state['section'];
829 }
830 else {
831 $form['#section'] = $this->display->id . '-' . $form_state['section'];
832 }
833
834 switch ($form_state['section']) {
835 case 'display_title':
836 $form['#title'] .= t('The name of this display');
837 $form['display_title'] = array(
838 '#type' => 'textfield',
839 '#description' => t('This title will appear only in the administrative interface for the View.'),
840 '#default_value' => $this->display->display_title,
841 );
842 break;
843 case 'title':
844 $form['#title'] .= t('The title of this view');
845 $form['title'] = array(
846 '#type' => 'textfield',
847 '#description' => t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc.'),
848 '#default_value' => $this->get_option('title'),
849 );
850 break;
851 case 'use_ajax':
852 $form['#title'] .= t('Use AJAX when available to load this view');
853 $form['description'] = array(
854 '#prefix' => '<div class="description form-item">',
855 '#suffix' => '</div>',
856 '#value' => t('If set, this view will use an AJAX mechanism for paging, table sorting and exposed filters. This means the entire page will not refresh. It is not recommended that you use this if this view is the main content of the page as it will prevent deep linking to specific pages, but it is very useful for side content.'),
857 );
858 $form['use_ajax'] = array(
859 '#type' => 'radios',
860 '#options' => array(1 => t('Yes'), 0 => t('No')),
861 '#default_value' => $this->get_option('use_ajax') ? 1 : 0,
862 );
863 break;
864 case 'use_pager':
865 $form['#title'] .= t('Use a pager for this view');
866 $form['use_pager'] = array(
867 '#type' => 'radios',
868 '#options' => array(TRUE => t('Full pager'), 'mini' => t('Mini pager'), 0 => t('No')),
869 '#default_value' => $this->get_option('use_pager'),
870 );
871 $form['pager_element'] = array(
872 '#type' => 'textfield',
873 '#title' => t('Pager element'),
874 '#description' => t("Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."),
875 '#default_value' => intval($this->get_option('pager_element')),
876 );
877 break;
878 case 'items_per_page':
879 $form['#title'] .= $this->use_pager() ? t('Items per page') : t('Items to display');
880
881 $form['items_per_page'] = array(
882 '#type' => 'textfield',
883 '#description' => t('The number of items to display per page. Enter 0 for no limit.'),
884 '#default_value' => intval($this->get_option('items_per_page')),
885 );
886 $form['offset'] = array(
887 '#type' => 'textfield',
888 '#title' => t('Offset'),
889 '#description' => t('The number of items to skip. For example, if this field is 3, the first 3 items will be skipped and not displayed. Offset can not be used if items to display is 0; instead use a very large number there.'),
890 '#default_value' => intval($this->get_option('offset')),
891 );
892 break;
893 case 'use_more':
894 $form['#title'] .= t('Add a more link to the bottom of the display.');
895 $form['use_more'] = array(
896 '#type' => 'checkbox',
897 '#title' => t('Create more link'),
898 '#description' => t("This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' above."),
899 '#default_value' => $this->get_option('use_more'),
900 );
901 $form['#title'] .= t('Text to use for the more link.');
902 $form['use_more_text'] = array(
903 '#type' => 'textfield',
904 '#title' => t('More link text'),
905 '#description' => t("The text to display for the more link."),
906 '#default_value' => $this->get_option('use_more_text'),
907 );
908 break;
909 case 'distinct':
910 $form['#title'] .= t('Display only distinct items, without duplicates.');
911 $form['distinct'] = array(
912 '#type' => 'checkbox',
913 '#title' => t('Distinct'),
914 '#description' => t('This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.'),
915 '#default_value' => $this->get_option('distinct'),
916 );
917 break;
918 case 'access':
919 $form['#title'] .= t('Access restrictions');
920 $form['access'] = array(
921 '#prefix' => '<div class="clear-block">',
922 '#suffix' => '</div>',
923 '#tree' => TRUE,
924 );
925
926 $access = $this->get_option('access');
927 $form['access']['type'] = array(
928 '#type' => 'radios',
929 '#options' => views_fetch_plugin_names('access'),
930 '#default_value' => $access['type'],
931 );
932
933 $access_plugin = views_fetch_plugin_data('access', $access['type']);
934 if (!empty($access_plugin['uses options'])) {
935 $form['markup'] = array(
936 '#prefix' => '<div class="form-item description">',
937 '#suffix' => '</div>',
938 '#value' => t('You may also adjust the !settings for the currently selected access restriction by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'access_options'))),
939 );
940 }
941
942 break;
943 case 'access_options':
944 $access = $this->get_option('access');
945 $plugin = $this->get_access_plugin();
946 $form['#title'] .= t('Access options');
947 if ($plugin) {
948 $form['#help_topic'] = $plugin->definition['help topic'];
949
950 $form['access_options'] = array(
951 '#tree' => TRUE,
952 );
953 $form['access_options']['type'] = array(
954 '#type' => 'value',
955 '#value' => $access['type'],
956 );
957 $plugin->options_form($form['access_options'], $form_state);
958 }
959 break;
960 case 'cache':
961 $form['#title'] .= t('Caching');
962 $form['cache'] = array(
963 '#prefix' => '<div class="clear-block">',
964 '#suffix' => '</div>',
965 '#tree' => TRUE,
966 );
967
968 $cache = $this->get_option('cache');
969 $form['cache']['type'] = array(
970 '#type' => 'radios',
971 '#options' => views_fetch_plugin_names('cache'),
972 '#default_value' => $cache['type'],
973 );
974
975 $cache_plugin = views_fetch_plugin_data('cache', $cache['type']);
976 if (!empty($cache_plugin['uses options'])) {
977 $form['markup'] = array(
978 '#prefix' => '<div class="form-item description">',
979 '#suffix' => '</div>',
980 '#value' => t('You may also adjust the !settings for the currently selected cache mechanism by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'cache_options'))),
981 );
982 }
983 break;
984 case 'cache_options':
985 $cache = $this->get_option('cache');
986 $plugin = $this->get_cache_plugin();
987 $form['#title'] .= t('Caching options');
988 if ($plugin) {
989 $form['#help_topic'] = $plugin->definition['help topic'];
990
991 $form['cache_options'] = array(
992 '#tree' => TRUE,
993 );
994 $form['cache_options']['type'] = array(
995 '#type' => 'value',
996 '#value' => $cache['type'],
997 );
998 $plugin->options_form($form['cache_options'], $form_state);
999 }
1000 break;
1001 case 'header':
1002 $form['#title'] .= t('Header');
1003 $form['header_empty'] = array(
1004 '#type' => 'checkbox',
1005 '#title' => t('Display even if view has no result'),
1006 '#default_value' => $this->get_option('header_empty'),
1007 );
1008 $form['header'] = array(
1009 '#type' => 'textarea',
1010 '#default_value' => $this->get_option('header'),
1011 '#rows' => 6,
1012 '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'),
1013 );
1014
1015 $form['header_format'] = filter_form($this->get_option('header_format'), NULL, array('header_format'));
1016 break;
1017 case 'footer':
1018 $form['#title'] .= t('Footer');
1019 $form['footer_empty'] = array(
1020 '#type' => 'checkbox',
1021 '#title' => t('Display even if view has no result'),
1022 '#default_value' => $this->get_option('footer_empty'),
1023 );
1024 $form['footer'] = array(
1025 '#type' => 'textarea',
1026 '#default_value' => $this->get_option('footer'),
1027 '#rows' => 6,
1028 '#description' => t('Text to display beneath the view. May contain an explanation or links or whatever you like. Optional.'),
1029 );
1030
1031 $form['footer_format'] = filter_form($this->get_option('footer_format'), NULL, array('footer_format'));
1032 break;
1033 case 'empty':
1034 $form['#title'] .= t('Empty text');
1035 $form['empty'] = array(
1036 '#type' => 'textarea',
1037 '#default_value' => $this->get_option('empty'),
1038 '#rows' => 6,
1039 '#description' => t('Text to display if the view has no results. Optional.'),
1040 );
1041
1042 $form['empty_format'] = filter_form($this->get_option('empty_format'), NULL, array('empty_format'));
1043 break;
1044 case 'style_plugin':
1045 $form['#title'] .= t('How should this view be styled');
1046 $form['#help_topic'] = 'style';
1047 $form['style_plugin'] = array(
1048 '#type' => 'radios',
1049 '#options' => views_fetch_plugin_names('style', $this->get_style_type(), array($this->view->base_table)),
1050 '#default_value' => $this->get_option('style_plugin'),
1051 '#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'),
1052 );
1053
1054 $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin'));
1055 if (!empty($style_plugin['uses options'])) {
1056 $form['markup'] = array(
1057 '#prefix' => '<div class="form-item description">',
1058 '#suffix' => '</div>',
1059 '#value' => t('You may also adjust the !settings for the currently selected style by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'style_options'))),
1060 );
1061 }
1062
1063 break;
1064 case 'style_options':
1065 $form['#title'] .= t('Style options');
1066 $style = TRUE;
1067 $type = 'style_plugin';
1068 $name = $this->get_option('style_plugin');
1069
1070 case 'row_options':
1071 if (!isset($name)) {
1072 $name = $this->get_option('row_plugin');
1073 }
1074 // if row, $style will be empty.
1075 if (empty($style)) {
1076 $form['#title'] .= t('Row style options');
1077 $type = 'row_plugin';
1078 }
1079 $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
1080 if ($plugin) {
1081 if (isset($plugin->definition['help topic'])) {
1082 $form['#help_topic'] = $plugin->definition['help topic'];
1083 }
1084 $form[$form_state['section']] = array(
1085 '#tree' => TRUE,
1086 );
1087 $plugin->options_form($form[$form_state['section']], $form_state);
1088 }
1089 break;
1090 case 'row_plugin':
1091 $form['#title'] .= t('How should each row in this view be styled');
1092 $form['#help_topic'] = 'style-row';
1093 $form['row_plugin'] = array(
1094 '#type' => 'radios',
1095 '#options' => views_fetch_plugin_names('row', $this->get_style_type(), array($this->view->base_table)),
1096 '#default_value' => $this->get_option('row_plugin'),
1097 );
1098
1099 $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
1100 if (!empty($row_plugin['uses options'])) {
1101 $form['markup'] = array(
1102 '#prefix' => '<div class="form-item description">',
1103 '#suffix' => '</div>',
1104 '#value' => t('You may also adjust the !settings for the currently selected row style by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'row_options'))),
1105 );
1106 }
1107
1108 break;
1109 case 'link_display':
1110 $form['#title'] .= t('Which display to use for path');
1111 foreach ($this->view->display as $display_id => $display) {
1112 if ($display->handler->has_path()) {
1113 $options[$display_id] = $display->display_title;
1114 }
1115 }
1116 $form['link_display'] = array(
1117 '#type' => 'radios',
1118 '#options' => $options,
1119 '#description' => t("Which display to use to get this display's path for things like summary links, rss feed links, more links, etc."),
1120 '#default_value' => $this->get_link_display(),
1121 );
1122