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'),
73 $pane_title = $this->get_option('pane_title');
74 if (empty($pane_title)) {
75 $pane_title = t('Use view name');
78 if (drupal_strlen($pane_title) > 16) {
79 $pane_title = drupal_substr($pane_title, 0, 16) . '...';
82 $options['pane_title'] = array(
83 'category' => 'panel_pane',
84 'title' => t('Admin title'),
85 'value' => $pane_title,
88 $pane_description = $this->get_option('pane_description');
89 if (empty($pane_description)) {
90 $pane_description = t('Use view description');
93 if (drupal_strlen($pane_description) > 16) {
94 $pane_description = drupal_substr($pane_description, 0, 16) . '...';
97 $options['pane_description'] = array(
98 'category' => 'panel_pane',
99 'title' => t('Admin desc'),
100 'value' => $pane_description,
103 $category = $this->get_option('pane_category');
104 $pane_category = $category['name'];
105 if (empty($pane_category)) {
106 $pane_category = t('View panes');
109 if (drupal_strlen($pane_category) > 16) {
110 $pane_category = drupal_substr($pane_category, 0, 16) . '...';
113 $options['pane_category'] = array(
114 'category' => 'panel_pane',
115 'title' => t('Category'),
116 'value' => $pane_category,
119 $options['link_to_view'] = array(
120 'category' => 'panel_pane',
121 'title' => t('Link to view'),
122 'value' => $this->get_option('link_to_view') ? t('Yes') : t('No'),
125 $options['inherit_panels_path'] = array(
126 'category' => 'panel_pane',
127 'title' => t('Use Panel path'),
128 'value' => $this->get_option('inherit_panels_path') ? t('Yes') : t('No'),
131 $options['argument_input'] = array(
132 'category' => 'panel_pane',
133 'title' => t('Argument input'),
134 'value' => t('Edit'),
137 $allow = $this->get_option('allow');
138 $filtered_allow = array_filter($allow);
140 $options['allow'] = array(
141 'category' => 'panel_pane',
142 'title' => t('Allow settings'),
143 'value' => empty($filtered_allow) ? t('None') : ($allow === $filtered_allow ? t('All') : t('Some')),
148 * Provide the default form for setting options.
150 function options_form(&$form, &$form_state) {
151 // It is very important to call the parent function here:
152 parent::options_form($form, $form_state);
154 switch ($form_state['section']) {
156 $form['#title'] .= t('Allow settings');
157 $form['description'] = array(
158 '#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>',
162 'use_pager' => t('Use pager'),
163 'items_per_page' => t('Items per page'),
164 'offset' => t('Pager offset'),
165 'link_to_view' => t('Link to view'),
166 'more_link' => t('More link'),
167 'path_override' => t('Path override'),
168 'title_override' => t('Title override'),
169 'exposed_form' => t('Use exposed widgets form as pane configuration'),
170 'fields_override' => t('Fields override'),
173 $allow = array_filter($this->get_option('allow'));
174 $form['allow'] = array(
175 '#type' => 'checkboxes',
176 '#default_value' => $allow,
177 '#options' => $options,
181 $form['#title'] .= t('Administrative title');
183 $form['pane_title'] = array(
184 '#type' => 'textfield',
185 '#default_value' => $this->get_option('pane_title'),
186 '#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.'),
190 case 'pane_description':
191 $form['#title'] .= t('Administrative description');
193 $form['pane_description'] = array(
194 '#type' => 'textfield',
195 '#default_value' => $this->get_option('pane_description'),
196 '#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.'),
200 case 'pane_category':
201 $form['#title'] .= t('Administrative description');
203 $cat = $this->get_option('pane_category');
204 $form['pane_category']['#tree'] = TRUE;
205 $form['pane_category']['name'] = array(
206 '#type' => 'textfield',
207 '#default_value' => $cat['name'],
208 '#description' => t('This is category the pane will appear in on the add content dialog.'),
210 $form['pane_category']['weight'] = array(
211 '#title' => t('Weight'),
212 '#type' => 'textfield',
213 '#default_value' => $cat['weight'],
214 '#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.'),
219 $form['#title'] .= t('Link pane title to view');
221 $form['link_to_view'] = array(
223 '#options' => array(1 => t('Yes'), 0 => t('No')),
224 '#default_value' => $this->get_option('link_to_view'),
228 case 'inherit_panels_path':
229 $form['#title'] .= t('Inherit path from panel display');
231 $form['inherit_panels_path'] = array(
233 '#options' => array(1 => t('Yes'), 0 => t('No')),
234 '#default_value' => $this->get_option('inherit_panels_path'),
235 '#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.'),
239 case 'argument_input':
240 $form['#title'] .= t('Choose the data source for view arguments');
241 $argument_input = $this->get_argument_input();
242 ctools_include('context');
243 ctools_include('dependent');
244 $form['argument_input']['#tree'] = TRUE;
246 $converters = ctools_context_get_all_converters();
249 foreach ($argument_input as $id => $argument) {
250 $form['argument_input'][$id] = array(
254 $safe = str_replace(array('][', '_', ' '), '-', $id);
255 $type_id = 'edit-argument-input-' . $safe;
257 $form['argument_input'][$id]['type'] = array(
260 'none' => t('No argument'),
261 'wildcard' => t('Argument wildcard'),
262 'context' => t('From context'),
263 'panel' => t('From panel argument'),
264 'fixed' => t('Fixed'),
265 'user' => t('Input on pane config'),
268 '#title' => t('@arg source', array('@arg' => $argument['name'])),
269 '#default_value' => $argument['type'],
271 $form['argument_input'][$id]['context'] = array(
273 '#title' => t('Required context'),
274 '#description' => t('If "From context" is selected, which type of context to use.'),
275 '#default_value' => $argument['context'],
276 '#options' => $converters,
277 '#dependency' => array($type_id => array('context')),
280 $form['argument_input'][$id]['context_optional'] = array(
281 '#type' => 'checkbox',
282 '#title' => t('Context is optional'),
283 '#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.'),
284 '#default_value' => $argument['context_optional'],
285 '#dependency' => array($type_id => array('context')),
288 $form['argument_input'][$id]['panel'] = array(
290 '#title' => t('Panel argument'),
291 '#description' => t('If "From panel argument" is selected, which panel argument to use.'),
292 '#default_value' => $argument['panel'],
293 '#options' => array(0 => t('First'), 1 => t('Second'), 2 => t('Third'), 3 => t('Fourth'), 4 => t('Fifth'), 5 => t('Sixth')),
294 '#dependency' => array($type_id => array('panel')),
297 $form['argument_input'][$id]['fixed'] = array(
298 '#type' => 'textfield',
299 '#title' => t('Fixed argument'),
300 '#description' => t('If "Fixed" is selected, what to use as an argument.'),
301 '#default_value' => $argument['fixed'],
302 '#dependency' => array($type_id => array('fixed')),
305 $form['argument_input'][$id]['label'] = array(
306 '#type' => 'textfield',
307 '#title' => t('Label'),
308 '#description' => t('If this argument is presented to the panels user, what label to apply to it.'),
309 '#default_value' => empty($argument['label']) ? $argument['name'] : $argument['label'],
310 '#dependency' => array($type_id => array('user')),
318 * Perform any necessary changes to the form values prior to storage.
319 * There is no need for this function to actually store the data.
321 function options_submit(&$form, &$form_state) {
322 // It is very important to call the parent function here:
323 parent::options_submit($form, $form_state);
324 switch ($form_state['section']) {
326 case 'argument_input':
328 case 'inherit_panels_path':
330 case 'pane_description':
331 case 'pane_category':
332 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
338 * Adjust the array of argument input to match the current list of
339 * arguments available for this display. This ensures that changing
340 * the arguments doesn't cause the argument input field to just
343 function get_argument_input() {
344 $arguments = $this->get_option('argument_input');
345 $handlers = $this->get_handlers('argument');
347 // We use a separate output so as to seamlessly discard info for
348 // arguments that no longer exist.
351 foreach ($handlers as $id => $handler) {
352 if (empty($arguments[$id])) {
353 $output[$id] = array(
356 'context_optional' => FALSE,
359 'name' => $handler->ui_name(),
363 $output[$id] = $arguments[$id];
364 $output[$id]['name'] = $handler->ui_name();
371 function use_more() {
372 $allow = $this->get_option('allow');
373 if (!$allow['more_link'] || !$this->has_pane_conf()) {
374 return parent::use_more();
376 $conf = $this->get_option('pane_conf');
377 return (bool) $conf['more_link'];
380 function get_path() {
381 if (empty($this->view->override_path)) {
382 return parent::get_path();
384 return $this->view->override_path;
388 if ($this->get_option('inherit_panels_path')) {
389 return $this->get_path();
391 return parent::get_url();
394 function uses_exposed_form_in_block() {
395 // We'll always allow the exposed form in a block, regardless of path.
400 * Determine if this display should display the exposed
401 * filters widgets, so the view will know whether or not
404 * Regardless of what this function
405 * returns, exposed filters will not be used nor
406 * displayed unless uses_exposed() returns TRUE.
408 function displays_exposed() {
409 $conf = $this->get_option('allow');
410 // If this is set, the exposed form is part of pane configuration, not
411 // rendered normally.
412 return empty($conf['exposed_form']);