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