5 * Contains the attachment display plugin.
9 * The plugin that handles an attachment display.
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.
15 * @ingroup views_display_plugins
17 class views_plugin_display_attachment extends views_plugin_display {
18 function option_definition () {
19 $options = parent::option_definition();
21 $options['displays'] = array('default' => array());
22 $options['attachment_position'] = array('default' => 'before');
23 $options['inherit_arguments'] = array('default' => TRUE, 'bool' => TRUE);
24 $options['inherit_exposed_filters'] = array('default' => FALSE, 'bool' => TRUE);
25 $options['inherit_pager'] = array('default' => FALSE, 'bool' => TRUE);
26 $options['render_pager'] = array('default' => FALSE, 'bool' => TRUE);
32 return $this->view->render($this->display->id);
35 function attachment_positions($position = NULL) {
37 'before' => t('Before'),
38 'after' => t('After'),
43 return $positions[$position];
50 * Provide the summary for attachment options in the views UI.
52 * This output is returned as an array.
54 function options_summary(&$categories, &$options) {
55 // It is very important to call the parent function here:
56 parent::options_summary($categories, $options);
58 $categories['attachment'] = array(
59 'title' => t('Attachment settings'),
66 $displays = array_filter($this->get_option('displays'));
67 if (count($displays) > 1) {
68 $attach_to = t('Multiple displays');
70 elseif (count($displays) == 1) {
71 $display = array_shift($displays);
72 if (!empty($this->view->display[$display])) {
73 $attach_to = check_plain($this->view->display[$display]->display_title);
77 if (!isset($attach_to)) {
78 $attach_to = t('Not defined');
81 $options['displays'] = array(
82 'category' => 'attachment',
83 'title' => t('Attach to'),
84 'value' => $attach_to,
87 $options['attachment_position'] = array(
88 'category' => 'attachment',
89 'title' => t('Attachment position'),
90 'value' => $this->attachment_positions($this->get_option('attachment_position')),
93 $options['inherit_arguments'] = array(
94 'category' => 'attachment',
95 'title' => t('Inherit contextual filters'),
96 'value' => $this->get_option('inherit_arguments') ? t('Yes') : t('No'),
99 $options['inherit_exposed_filters'] = array(
100 'category' => 'attachment',
101 'title' => t('Inherit exposed filters'),
102 'value' => $this->get_option('inherit_exposed_filters') ? t('Yes') : t('No'),
105 $options['inherit_pager'] = array(
106 'category' => 'pager',
107 'title' => t('Inherit pager'),
108 'value' => $this->get_option('inherit_pager') ? t('Yes') : t('No'),
111 $options['render_pager'] = array(
112 'category' => 'pager',
113 'title' => t('Render pager'),
114 'value' => $this->get_option('render_pager') ? t('Yes') : t('No'),
120 * Provide the default form for setting options.
122 function options_form(&$form, &$form_state) {
123 // It is very important to call the parent function here:
124 parent::options_form($form, $form_state);
126 switch ($form_state['section']) {
127 case 'inherit_arguments':
128 $form['#title'] .= t('Inherit contextual filters');
129 $form['inherit_arguments'] = array(
130 '#type' => 'checkbox',
131 '#title' => t('Inherit'),
132 '#description' => t('Should this display inherit its contextual filter values from the parent display to which it is attached?'),
133 '#default_value' => $this->get_option('inherit_arguments'),
136 case 'inherit_exposed_filters':
137 $form['#title'] .= t('Inherit exposed filters');
138 $form['inherit_exposed_filters'] = array(
139 '#type' => 'checkbox',
140 '#title' => t('Inherit'),
141 '#description' => t('Should this display inherit its exposed filter values from the parent display to which it is attached?'),
142 '#default_value' => $this->get_option('inherit_exposed_filters'),
145 case 'inherit_pager':
146 $form['#title'] .= t('Inherit pager');
147 $form['inherit_pager'] = array(
148 '#type' => 'checkbox',
149 '#title' => t('Inherit'),
150 '#description' => t('Should this display inherit its paging values from the parent display to which it is attached?'),
151 '#default_value' => $this->get_option('inherit_pager'),
155 $form['#title'] .= t('Render pager');
156 $form['render_pager'] = array(
157 '#type' => 'checkbox',
158 '#title' => t('Render'),
159 '#description' => t('Should this display render the pager values? This is only meaningful if inheriting a pager.'),
160 '#default_value' => $this->get_option('render_pager'),
163 case 'attachment_position':
164 $form['#title'] .= t('Position');
165 $form['attachment_position'] = array(
167 '#description' => t('Attach before or after the parent display?'),
168 '#options' => $this->attachment_positions(),
169 '#default_value' => $this->get_option('attachment_position'),
173 $form['#title'] .= t('Attach to');
175 foreach ($this->view->display as $display_id => $display) {
176 if (!empty($display->handler) && $display->handler->accept_attachments()) {
177 $displays[$display_id] = $display->display_title;
180 $form['displays'] = array(
181 '#type' => 'checkboxes',
182 '#description' => t('Select which display or displays this should attach to.'),
183 '#options' => $displays,
184 '#default_value' => $this->get_option('displays'),
191 * Perform any necessary changes to the form values prior to storage.
192 * There is no need for this function to actually store the data.
194 function options_submit(&$form, &$form_state) {
195 // It is very important to call the parent function here:
196 parent::options_submit($form, $form_state);
197 switch ($form_state['section']) {
198 case 'inherit_arguments':
199 case 'inherit_pager':
201 case 'inherit_exposed_filters':
202 case 'attachment_position':
204 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
210 * Attach to another view.
212 function attach_to($display_id) {
213 $displays = $this->get_option('displays');
215 if (empty($displays[$display_id])) {
219 if (!$this->access()) {
223 // Get a fresh view because our current one has a lot of stuff on it because it's
224 // already been executed.
225 $view = $this->view->clone_view();
226 $view->original_args = $view->args;
228 $args = $this->get_option('inherit_arguments') ? $this->view->args : array();
229 $view->set_arguments($args);
230 $exposed_input = $this->get_option('inherit_exposed_filters') ? $this->view->exposed_input : array();
231 $view->set_exposed_input($exposed_input);
232 $view->set_display($this->display->id);
233 if ($this->get_option('inherit_pager')) {
234 $view->display_handler->use_pager = $this->view->display[$display_id]->handler->use_pager();
235 $view->display_handler->set_option('pager', $this->view->display[$display_id]->handler->get_option('pager'));
238 $attachment = $view->execute_display($this->display->id, $args);
240 switch ($this->get_option('attachment_position')) {
242 $this->view->attachment_before .= $attachment;
245 $this->view->attachment_after .= $attachment;
248 $this->view->attachment_before .= $attachment;
249 $this->view->attachment_after .= $attachment;
257 * Attachment displays only use exposed widgets if
258 * they are set to inherit the exposed filter settings
259 * of their parent display.
261 function uses_exposed() {
262 if (!empty($this->options['inherit_exposed_filters']) && parent::uses_exposed()) {
269 * If an attachment is set to inherit the exposed filter
270 * settings from its parent display, then don't render and
271 * display a second set of exposed filter widgets.
273 function displays_exposed() {
274 return $this->options['inherit_exposed_filters'] ? FALSE : TRUE;
277 function use_pager() {
278 return !empty($this->use_pager);
281 function render_pager() {
282 return !empty($this->use_pager) && $this->get_option('render_pager');