00001 <?php
00016 class views_plugin_display_attachment extends views_plugin_display {
00017 function option_definition () {
00018 $options = parent::option_definition();
00019
00020 $options['displays'] = array('default' => array());
00021 $options['attachment_position'] = array('default' => 'before');
00022 $options['inherit_arguments'] = array('default' => TRUE);
00023 $options['inherit_exposed_filters'] = array('default' => FALSE);
00024 $options['inherit_pager'] = array('default' => FALSE);
00025 $options['render_pager'] = array('default' => FALSE);
00026
00027 return $options;
00028 }
00029
00030 function execute() {
00031 return $this->view->render($this->display->id);
00032 }
00033
00034 function attachment_positions($position = NULL) {
00035 $positions = array(
00036 'before' => t('Before'),
00037 'after' => t('After'),
00038 'both' => t('Both'),
00039 );
00040
00041 if ($position) {
00042 return $positions[$position];
00043 }
00044
00045 return $positions;
00046 }
00047
00053 function options_summary(&$categories, &$options) {
00054
00055 parent::options_summary($categories, $options);
00056
00057 $categories['attachment'] = array(
00058 'title' => t('Attachment settings'),
00059 'column' => 'second',
00060 'build' => array(
00061 '#weight' => -10,
00062 ),
00063 );
00064
00065 $displays = array_filter($this->get_option('displays'));
00066 if (count($displays) > 1) {
00067 $attach_to = t('Multiple displays');
00068 }
00069 elseif (count($displays) == 1) {
00070 $display = array_shift($displays);
00071 if (!empty($this->view->display[$display])) {
00072 $attach_to = check_plain($this->view->display[$display]->display_title);
00073 }
00074 }
00075
00076 if (!isset($attach_to)) {
00077 $attach_to = t('Not defined');
00078 }
00079
00080 $options['displays'] = array(
00081 'category' => 'attachment',
00082 'title' => t('Attach to'),
00083 'value' => $attach_to,
00084 );
00085
00086 $options['attachment_position'] = array(
00087 'category' => 'attachment',
00088 'title' => t('Attachment position'),
00089 'value' => $this->attachment_positions($this->get_option('attachment_position')),
00090 );
00091
00092 $options['inherit_arguments'] = array(
00093 'category' => 'attachment',
00094 'title' => t('Inherit contextual filters'),
00095 'value' => $this->get_option('inherit_arguments') ? t('Yes') : t('No'),
00096 );
00097
00098 $options['inherit_exposed_filters'] = array(
00099 'category' => 'attachment',
00100 'title' => t('Inherit exposed filters'),
00101 'value' => $this->get_option('inherit_exposed_filters') ? t('Yes') : t('No'),
00102 );
00103
00104 $options['inherit_pager'] = array(
00105 'category' => 'pager',
00106 'title' => t('Inherit pager'),
00107 'value' => $this->get_option('inherit_pager') ? t('Yes') : t('No'),
00108 );
00109
00110 $options['render_pager'] = array(
00111 'category' => 'pager',
00112 'title' => t('Render pager'),
00113 'value' => $this->get_option('render_pager') ? t('Yes') : t('No'),
00114 );
00115
00116 }
00117
00121 function options_form(&$form, &$form_state) {
00122
00123 parent::options_form($form, $form_state);
00124
00125 switch ($form_state['section']) {
00126 case 'inherit_arguments':
00127 $form['#title'] .= t('Inherit contextual filters');
00128 $form['inherit_arguments'] = array(
00129 '#type' => 'checkbox',
00130 '#title' => t('Inherit'),
00131 '#description' => t('Should this display inherit its contextual filter values from the parent display to which it is attached?'),
00132 '#default_value' => $this->get_option('inherit_arguments'),
00133 );
00134 break;
00135 case 'inherit_exposed_filters':
00136 $form['#title'] .= t('Inherit exposed filters');
00137 $form['inherit_exposed_filters'] = array(
00138 '#type' => 'checkbox',
00139 '#title' => t('Inherit'),
00140 '#description' => t('Should this display inherit its exposed filter values from the parent display to which it is attached?'),
00141 '#default_value' => $this->get_option('inherit_exposed_filters'),
00142 );
00143 break;
00144 case 'inherit_pager':
00145 $form['#title'] .= t('Inherit pager');
00146 $form['inherit_pager'] = array(
00147 '#type' => 'checkbox',
00148 '#title' => t('Inherit'),
00149 '#description' => t('Should this display inherit its paging values from the parent display to which it is attached?'),
00150 '#default_value' => $this->get_option('inherit_pager'),
00151 );
00152 break;
00153 case 'render_pager':
00154 $form['#title'] .= t('Render pager');
00155 $form['render_pager'] = array(
00156 '#type' => 'checkbox',
00157 '#title' => t('Render'),
00158 '#description' => t('Should this display render the pager values? This is only meaningful if inheriting a pager.'),
00159 '#default_value' => $this->get_option('render_pager'),
00160 );
00161 break;
00162 case 'attachment_position':
00163 $form['#title'] .= t('Position');
00164 $form['attachment_position'] = array(
00165 '#type' => 'radios',
00166 '#description' => t('Attach before or after the parent display?'),
00167 '#options' => $this->attachment_positions(),
00168 '#default_value' => $this->get_option('attachment_position'),
00169 );
00170 break;
00171 case 'displays':
00172 $form['#title'] .= t('Attach to');
00173 $displays = array();
00174 foreach ($this->view->display as $display_id => $display) {
00175 if (!empty($display->handler) && $display->handler->accept_attachments()) {
00176 $displays[$display_id] = $display->display_title;
00177 }
00178 }
00179 $form['displays'] = array(
00180 '#type' => 'checkboxes',
00181 '#description' => t('Select which display or displays this should attach to.'),
00182 '#options' => $displays,
00183 '#default_value' => $this->get_option('displays'),
00184 );
00185 break;
00186 }
00187 }
00188
00193 function options_submit(&$form, &$form_state) {
00194
00195 parent::options_submit($form, $form_state);
00196 switch ($form_state['section']) {
00197 case 'inherit_arguments':
00198 case 'inherit_pager':
00199 case 'render_pager':
00200 case 'inherit_exposed_filters':
00201 case 'attachment_position':
00202 case 'displays':
00203 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
00204 break;
00205 }
00206 }
00207
00211 function attach_to($display_id) {
00212 $displays = $this->get_option('displays');
00213
00214 if (empty($displays[$display_id])) {
00215 return;
00216 }
00217
00218 if (!$this->access()) {
00219 return;
00220 }
00221
00222
00223
00224 $view = $this->view->clone_view();
00225 $view->original_args = $view->args;
00226
00227 $args = $this->get_option('inherit_arguments') ? $this->view->args : array();
00228 $view->set_arguments($args);
00229 $view->set_display($this->display->id);
00230 if ($this->get_option('inherit_pager')) {
00231 $view->display_handler->use_pager = $this->view->display[$display_id]->handler->use_pager();
00232 $view->display_handler->set_option('pager', $this->view->display[$display_id]->handler->get_option('pager'));
00233 }
00234
00235 $attachment = $view->execute_display($this->display->id, $args);
00236
00237 switch ($this->get_option('attachment_position')) {
00238 case 'before':
00239 $this->view->attachment_before .= $attachment;
00240 break;
00241 case 'after':
00242 $this->view->attachment_after .= $attachment;
00243 break;
00244 case 'both':
00245 $this->view->attachment_before .= $attachment;
00246 $this->view->attachment_after .= $attachment;
00247 break;
00248 }
00249
00250 $view->destroy();
00251 }
00252
00258 function uses_exposed() {
00259 if (!empty($this->options['inherit_exposed_filters']) && parent::uses_exposed()) {
00260 return TRUE;
00261 }
00262 return FALSE;
00263 }
00264
00270 function displays_exposed() {
00271 return $this->options['inherit_exposed_filters'] ? FALSE : TRUE;
00272 }
00273
00274 function use_pager() {
00275 return !empty($this->use_pager);
00276 }
00277
00278 function render_pager() {
00279 return !empty($this->use_pager) && $this->get_option('render_pager');
00280 }
00281 }