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

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

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


Revision 1.6 - (show annotations) (download) (as text)
Fri Jun 26 00:23:42 2009 UTC (5 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.5: +2 -2 lines
File MIME type: text/x-php
#466454 by neclimdul: PHP strict fixes.
1 <?php
2 // $Id: views_plugin_display_attachment.inc,v 1.5 2009/06/25 22:19:45 merlinofchaos Exp $
3 /**
4 * @file
5 * Contains the attachment display plugin.
6 */
7
8 /**
9 * The plugin that handles an attachment display.
10 *
11 * Attachment displays are secondary displays that are 'attached' to a primary
12 * display. Effectively they are a simple way to get multiple views within
13 * the same view. They can share some information.
14 *
15 * @ingroup views_display_plugins
16 */
17 class views_plugin_display_attachment extends views_plugin_display {
18 function option_definition () {
19 $options = parent::option_definition();
20
21 $options['attachment_position'] = array('default' => 'before');
22 $options['inherit_arguments'] = array('default' => TRUE);
23 $options['inherit_exposed_filters'] = array('default' => FALSE);
24 $options['displays'] = array('default' => array());
25
26 return $options;
27 }
28
29 function execute() {
30 return $this->view->render($this->display->id);
31 }
32
33 function attachment_positions($position = NULL) {
34 $positions = array(
35 'before' => t('Before'),
36 'after' => t('After'),
37 'both' => t('Both'),
38 );
39
40 if ($position) {
41 return $positions[$position];
42 }
43
44 return $positions;
45 }
46
47 /**
48 * Provide the summary for attachment options in the views UI.
49 *
50 * This output is returned as an array.
51 */
52 function options_summary(&$categories, &$options) {
53 // It is very important to call the parent function here:
54 parent::options_summary($categories, $options);
55
56 $categories['attachment'] = array(
57 'title' => t('Attachment settings'),
58 );
59
60 $options['inherit_arguments'] = array(
61 'category' => 'attachment',
62 'title' => t('Inherit arguments'),
63 'value' => $this->get_option('inherit_arguments') ? t('Yes') : t('No'),
64 );
65
66 $options['inherit_exposed_filters'] = array(
67 'category' => 'attachment',
68 'title' => t('Inherit exposed filters'),
69 'value' => $this->get_option('inherit_exposed_filters') ? t('Yes') : t('No'),
70 );
71
72 $options['attachment_position'] = array(
73 'category' => 'attachment',
74 'title' => t('Position'),
75 'value' => $this->attachment_positions($this->get_option('attachment_position')),
76 );
77
78 $displays = array_filter($this->get_option('displays'));
79 if (count($displays) > 1) {
80 $attach_to = t('Multiple displays');
81 }
82 else if (count($displays) == 1) {
83 $display = array_shift($displays);
84 if (!empty($this->view->display[$display])) {
85 $attach_to = check_plain($this->view->display[$display]->display_title);
86 }
87 }
88
89 if (!isset($attach_to)) {
90 $attach_to = t('None');
91 }
92
93 $options['displays'] = array(
94 'category' => 'attachment',
95 'title' => t('Attach to'),
96 'value' => $attach_to,
97 );
98 }
99
100 /**
101 * Provide the default form for setting options.
102 */
103 function options_form(&$form, &$form_state) {
104 // It is very important to call the parent function here:
105 parent::options_form($form, $form_state);
106
107 switch ($form_state['section']) {
108 case 'inherit_arguments':
109 $form['#title'] .= t('Inherit arguments');
110 $form['inherit_arguments'] = array(
111 '#type' => 'checkbox',
112 '#title' => t('Inherit'),
113 '#description' => t('Should this display inherit its arguments from the parent display to which it is attached?'),
114 '#default_value' => $this->get_option('inherit_arguments'),
115 );
116 break;
117 case 'inherit_exposed_filters':
118 $form['#title'] .= t('Inherit exposed filters');
119 $form['inherit_exposed_filters'] = array(
120 '#type' => 'checkbox',
121 '#title' => t('Inherit'),
122 '#description' => t('Should this display inherit its exposed filter values from the parent display to which it is attached?'),
123 '#default_value' => $this->get_option('inherit_exposed_filters'),
124 );
125 break;
126 case 'attachment_position':
127 $form['#title'] .= t('Position');
128 $form['attachment_position'] = array(
129 '#type' => 'radios',
130 '#description' => t('Attach before or after the parent display?'),
131 '#options' => $this->attachment_positions(),
132 '#default_value' => $this->get_option('attachment_position'),
133 );
134 break;
135 case 'displays':
136 $form['#title'] .= t('Attach to');
137 $displays = array();
138 foreach ($this->view->display as $display_id => $display) {
139 if (!empty($display->handler) && $display->handler->accept_attachments()) {
140 $displays[$display_id] = $display->display_title;
141 }
142 }
143 $form['displays'] = array(
144 '#type' => 'checkboxes',
145 '#description' => t('Select which display or displays this should attach to.'),
146 '#options' => $displays,
147 '#default_value' => $this->get_option('displays'),
148 );
149 break;
150 }
151 }
152
153 /**
154 * Perform any necessary changes to the form values prior to storage.
155 * There is no need for this function to actually store the data.
156 */
157 function options_submit(&$form, &$form_state) {
158 // It is very important to call the parent function here:
159 parent::options_submit($form, $form_state);
160 switch ($form_state['section']) {
161 case 'inherit_arguments':
162 case 'inherit_exposed_filters':
163 case 'attachment_position':
164 case 'displays':
165 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
166 break;
167 }
168 }
169
170 /**
171 * Attach to another view.
172 */
173 function attach_to($display_id) {
174 $displays = $this->get_option('displays');
175
176 if (empty($displays[$display_id])) {
177 return;
178 }
179
180 if (!$this->access()) {
181 return;
182 }
183
184 // Get a fresh view because our current one has a lot of stuff on it because it's
185 // already been executed.
186 $view = $this->view->clone_view();
187 $view->original_args = $view->args;
188
189 $args = $this->get_option('inherit_arguments') ? $this->view->args : array();
190 $view->set_arguments($args);
191
192 // because of this, it is very very important that displays that can accept
193 // attachments not also be attachments, or this could explode messily.
194 $attachment = $view->execute_display($this->display->id, $args);
195
196 switch ($this->get_option('attachment_position')) {
197 case 'before':
198 $this->view->attachment_before .= $attachment;
199 break;
200 case 'after':
201 $this->view->attachment_after .= $attachment;
202 break;
203 case 'both':
204 $this->view->attachment_before .= $attachment;
205 $this->view->attachment_after .= $attachment;
206 break;
207 }
208
209 $view->destroy();
210 }
211
212 /**
213 * Attachment displays only use exposed widgets if
214 * they are set to inherit the exposed filter settings
215 * of their parent display.
216 */
217 function uses_exposed() {
218 if (!empty($this->options['inherit_exposed_filters']) && parent::uses_exposed()) {
219 return TRUE;
220 }
221 return FALSE;
222 }
223
224 /**
225 * If an attachment is set to inherit the exposed filter
226 * settings from its parent display, then don't render and
227 * display a second set of exposed filter widgets.
228 */
229 function displays_exposed() {
230 return $this->options['inherit_exposed_filters'] ? FALSE : TRUE;
231 }
232 }

  ViewVC Help
Powered by ViewVC 1.1.2