| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: views_plugin_display_attachment.inc,v 1.6.2.1 2009/11/30 19:05:47 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['inherit_pager'] = array('default' => FALSE); 25 $options['render_pager'] = array('default' => TRUE); 26 $options['displays'] = array('default' => array()); 27 28 return $options; 29 } 30 31 function execute() { 32 return $this->view->render($this->display->id); 33 } 34 35 function attachment_positions($position = NULL) { 36 $positions = array( 37 'before' => t('Before'), 38 'after' => t('After'), 39 'both' => t('Both'), 40 ); 41 42 if ($position) { 43 return $positions[$position]; 44 } 45 46 return $positions; 47 } 48 49 /** 50 * Provide the summary for attachment options in the views UI. 51 * 52 * This output is returned as an array. 53 */ 54 function options_summary(&$categories, &$options) { 55 // It is very important to call the parent function here: 56 parent::options_summary($categories, $options); 57 58 $categories['attachment'] = array( 59 'title' => t('Attachment settings'), 60 ); 61 62 $options['inherit_arguments'] = array( 63 'category' => 'attachment', 64 'title' => t('Inherit arguments'), 65 'value' => $this->get_option('inherit_arguments') ? t('Yes') : t('No'), 66 ); 67 68 $options['inherit_exposed_filters'] = array( 69 'category' => 'attachment', 70 'title' => t('Inherit exposed filters'), 71 'value' => $this->get_option('inherit_exposed_filters') ? t('Yes') : t('No'), 72 ); 73 74 $options['inherit_pager'] = array( 75 'category' => 'attachment', 76 'title' => t('Inherit pager'), 77 'value' => $this->get_option('inherit_pager') ? t('Yes') : t('No'), 78 ); 79 80 $options['render_pager'] = array( 81 'category' => 'attachment', 82 'title' => t('Render pager'), 83 'value' => $this->get_option('render_pager') ? t('Yes') : t('No'), 84 ); 85 86 $options['attachment_position'] = array( 87 'category' => 'attachment', 88 'title' => t('Position'), 89 'value' => $this->attachment_positions($this->get_option('attachment_position')), 90 ); 91 92 $displays = array_filter($this->get_option('displays')); 93 if (count($displays) > 1) { 94 $attach_to = t('Multiple displays'); 95 } 96 else if (count($displays) == 1) { 97 $display = array_shift($displays); 98 if (!empty($this->view->display[$display])) { 99 $attach_to = check_plain($this->view->display[$display]->display_title); 100 } 101 } 102 103 if (!isset($attach_to)) { 104 $attach_to = t('None'); 105 } 106 107 $options['displays'] = array( 108 'category' => 'attachment', 109 'title' => t('Attach to'), 110 'value' => $attach_to, 111 ); 112 } 113 114 /** 115 * Provide the default form for setting options. 116 */ 117 function options_form(&$form, &$form_state) { 118 // It is very important to call the parent function here: 119 parent::options_form($form, $form_state); 120 121 switch ($form_state['section']) { 122 case 'inherit_arguments': 123 $form['#title'] .= t('Inherit arguments'); 124 $form['inherit_arguments'] = array( 125 '#type' => 'checkbox', 126 '#title' => t('Inherit'), 127 '#description' => t('Should this display inherit its arguments from the parent display to which it is attached?'), 128 '#default_value' => $this->get_option('inherit_arguments'), 129 ); 130 break; 131 case 'inherit_exposed_filters': 132 $form['#title'] .= t('Inherit exposed filters'); 133 $form['inherit_exposed_filters'] = array( 134 '#type' => 'checkbox', 135 '#title' => t('Inherit'), 136 '#description' => t('Should this display inherit its exposed filter values from the parent display to which it is attached?'), 137 '#default_value' => $this->get_option('inherit_exposed_filters'), 138 ); 139 break; 140 case 'inherit_pager': 141 $form['#title'] .= t('Inherit pager'); 142 $form['inherit_pager'] = array( 143 '#type' => 'checkbox', 144 '#title' => t('Inherit'), 145 '#description' => t('Should this display inherit its paging values from the parent display to which it is attached? Note that this will provide unexpected results if the number of items to display do not match.'), 146 '#default_value' => $this->get_option('inherit_pager'), 147 ); 148 break; 149 case 'render_pager': 150 $form['#title'] .= t('Render pager'); 151 $form['render_pager'] = array( 152 '#type' => 'checkbox', 153 '#title' => t('Render'), 154 '#description' => t('Should this display render the pager values? If not it can inherit from the parent...'), 155 '#default_value' => $this->get_option('render_pager'), 156 ); 157 break; 158 case 'attachment_position': 159 $form['#title'] .= t('Position'); 160 $form['attachment_position'] = array( 161 '#type' => 'radios', 162 '#description' => t('Attach before or after the parent display?'), 163 '#options' => $this->attachment_positions(), 164 '#default_value' => $this->get_option('attachment_position'), 165 ); 166 break; 167 case 'displays': 168 $form['#title'] .= t('Attach to'); 169 $displays = array(); 170 foreach ($this->view->display as $display_id => $display) { 171 if (!empty($display->handler) && $display->handler->accept_attachments()) { 172 $displays[$display_id] = $display->display_title; 173 } 174 } 175 $form['displays'] = array( 176 '#type' => 'checkboxes', 177 '#description' => t('Select which display or displays this should attach to.'), 178 '#options' => $displays, 179 '#default_value' => $this->get_option('displays'), 180 ); 181 break; 182 } 183 } 184 185 /** 186 * Perform any necessary changes to the form values prior to storage. 187 * There is no need for this function to actually store the data. 188 */ 189 function options_submit(&$form, &$form_state) { 190 // It is very important to call the parent function here: 191 parent::options_submit($form, $form_state); 192 switch ($form_state['section']) { 193 case 'inherit_arguments': 194 case 'inherit_pager': 195 case 'render_pager': 196 case 'inherit_exposed_filters': 197 case 'attachment_position': 198 case 'displays': 199 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]); 200 break; 201 } 202 } 203 204 /** 205 * Attach to another view. 206 */ 207 function attach_to($display_id) { 208 $displays = $this->get_option('displays'); 209 210 if (empty($displays[$display_id])) { 211 return; 212 } 213 214 if (!$this->access()) { 215 return; 216 } 217 218 // Get a fresh view because our current one has a lot of stuff on it because it's 219 // already been executed. 220 $view = $this->view->clone_view(); 221 $view->original_args = $view->args; 222 223 $args = $this->get_option('inherit_arguments') ? $this->view->args : array(); 224 $view->set_arguments($args); 225 $view->set_display($this->display->id); 226 if ($this->get_option('inherit_pager')) { 227 $view->display_handler->use_pager = $this->view->display[$display_id]->handler->use_pager(); 228 $view->display_handler->set_option('pager_element', $this->view->display[$display_id]->handler->get_option('pager_element')); 229 } 230 231 // because of this, it is very very important that displays that can accept 232 // attachments not also be attachments, or this could explode messily. 233 $attachment = $view->execute_display($this->display->id, $args); 234 235 switch ($this->get_option('attachment_position')) { 236 case 'before': 237 $this->view->attachment_before .= $attachment; 238 break; 239 case 'after': 240 $this->view->attachment_after .= $attachment; 241 break; 242 case 'both': 243 $this->view->attachment_before .= $attachment; 244 $this->view->attachment_after .= $attachment; 245 break; 246 } 247 248 $view->destroy(); 249 } 250 251 /** 252 * Attachment displays only use exposed widgets if 253 * they are set to inherit the exposed filter settings 254 * of their parent display. 255 */ 256 function uses_exposed() { 257 if (!empty($this->options['inherit_exposed_filters']) && parent::uses_exposed()) { 258 return TRUE; 259 } 260 return FALSE; 261 } 262 263 /** 264 * If an attachment is set to inherit the exposed filter 265 * settings from its parent display, then don't render and 266 * display a second set of exposed filter widgets. 267 */ 268 function displays_exposed() { 269 return $this->options['inherit_exposed_filters'] ? FALSE : TRUE; 270 } 271 272 function use_pager() { 273 return !empty($this->use_pager); 274 } 275 276 function render_pager() { 277 return !empty($this->use_pager) && $this->get_option('render_pager'); 278 } 279 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |