4 * The plugin that handles a panel_pane.
6 class views_content_plugin_display_panel_pane
extends views_plugin_display
{
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.
11 var
$panel_pane_display = TRUE
;
12 var
$has_pane_conf = NULL
;
14 function option_definition() {
15 $options = parent
::option_definition();
17 $options['pane_title'] = array('default' => '', 'translatable' => TRUE
);
18 $options['pane_description'] = array('default' => '', 'translatable' => TRUE
);
19 $options['pane_category'] = array(
21 'name' => array('default' => 'View panes', 'translatable' => TRUE
),
22 'weight' => array('default' => 0),
26 $options['allow'] = 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
),
40 $options['argument_input'] = array('default' => array());
41 $options['link_to_view'] = array('default' => 0);
42 $options['inherit_panels_path'] = array('default' => 0);
47 function has_pane_conf() {
48 return isset($this->has_pane_conf
);
51 function set_pane_conf($conf = array()) {
52 $this->set_option('pane_conf', $conf);
53 $this->has_pane_conf
= TRUE
;
57 * Provide the summary for page options in the views UI.
59 * This output is returned as an array.
61 function options_summary(&$categories, &$options) {
62 // It is very important to call the parent function here:
63 parent
::options_summary($categories, $options);
65 $categories['panel_pane'] = array(
66 'title' => t('Pane settings'),
69 $pane_title = $this->get_option('pane_title');
70 if (empty($pane_title)) {
71 $pane_title = t('Use view name');
74 if (strlen($pane_title) > 16) {
75 $pane_title = substr($pane_title, 0, 16) .
'...';
78 $options['pane_title'] = array(
79 'category' => 'panel_pane',
80 'title' => t('Admin title'),
81 'value' => $pane_title,
84 $pane_description = $this->get_option('pane_description');
85 if (empty($pane_description)) {
86 $pane_description = t('Use view description');
89 if (strlen($pane_description) > 16) {
90 $pane_description = substr($pane_description, 0, 16) .
'...';
93 $options['pane_description'] = array(
94 'category' => 'panel_pane',
95 'title' => t('Admin desc'),
96 'value' => $pane_description,
99 $category = $this->get_option('pane_category');
100 $pane_category = $category['name'];
101 if (empty($pane_category)) {
102 $pane_category = t('View panes');
105 if (strlen($pane_category) > 16) {
106 $pane_category = substr($pane_category, 0, 16) .
'...';
109 $options['pane_category'] = array(
110 'category' => 'panel_pane',
111 'title' => t('Category'),
112 'value' => $pane_category,
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'),
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'),
127 $options['argument_input'] = array(
128 'category' => 'panel_pane',
129 'title' => t('Argument input'),
130 'value' => t('Edit'),
133 $allow = $this->get_option('allow');
134 $filtered_allow = array_filter($allow);
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')),
144 * Provide the default form for setting options.
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);
150 switch ($form_state['section']) {
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>',
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'),
169 $allow = array_filter($this->get_option('allow'));
170 $form['allow'] = array(
171 '#type' => 'checkboxes',
172 '#default_value' => $allow,
173 '#options' => $options,
177 $form['#title'] .
= t('Administrative title');
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.'),
186 case
'pane_description':
187 $form['#title'] .
= t('Administrative description');
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.'),
196 case
'pane_category':
197 $form['#title'] .
= t('Administrative description');
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.'),
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.'),
215 $form['#title'] .
= t('Link pane title to view');
217 $form['link_to_view'] = array(
219 '#options' => array(1 => t('Yes'), 0 => t('No')),
220 '#default_value' => $this->get_option('link_to_view'),
224 case
'inherit_panels_path':
225 $form['#title'] .
= t('Inherit path from panel display');
227 $form['inherit_panels_path'] = array(
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.'),
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
;
242 foreach ($argument_input as
$id => $argument) {
243 $form['argument_input'][$id] = array(
247 $safe = str_replace(array('][', '_', ' '), '-', $id);
248 $type_id = 'edit-argument-input-' .
$safe;
250 $form['argument_input'][$id]['type'] = 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'),
261 '#title' => t('@arg source', array('@arg' => $argument['name'])),
262 '#default_value' => $argument['type'],
265 $form['argument_input'][$id]['context'] = array(
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')),
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')),
284 $form['argument_input'][$id]['panel'] = array(
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')),
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')),
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')),
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.
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']) {
325 case
'argument_input':
327 case
'inherit_panels_path':
329 case
'pane_description':
330 case
'pane_category':
331 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
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
342 function get_argument_input() {
343 $arguments = $this->get_option('argument_input');
344 $handlers = $this->get_handlers('argument');
346 // We use a separate output so as to seamlessly discard info for
347 // arguments that no longer exist.
350 foreach ($handlers as
$id => $handler) {
351 if (empty($arguments[$id])) {
352 $output[$id] = array(
355 'context_optional' => FALSE
,
358 'name' => $handler->ui_name(),
362 $output[$id] = $arguments[$id];
363 $output[$id]['name'] = $handler->ui_name();
370 function use_more() {
371 $allow = $this->get_option('allow');
372 if (!$allow['more_link'] || !$this->has_pane_conf()) {
373 return parent
::use_more();
375 $conf = $this->get_option('pane_conf');
376 return (bool
) $conf['more_link'];
379 function get_path() {
380 if (empty($this->view
->override_path
)) {
381 return parent
::get_path();
383 return $this->view
->override_path
;
387 * Determine if this display should display the exposed
388 * filters widgets, so the view will know whether or not
391 * Regardless of what this function
392 * returns, exposed filters will not be used nor
393 * displayed unless uses_exposed() returns TRUE.
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']);