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