class Attachment in Views (for Drupal 7) 8.3
The plugin that handles an attachment display.
Attachment displays are secondary displays that are 'attached' to a primary display. Effectively they are a simple way to get multiple views within the same view. They can share some information.
Plugin annotation
@Plugin(
id = "attachment",
title = @Translation("Attachment"),
help = @Translation("Attachments added to other displays to achieve multiple views in the same view."),
theme = "views_view",
contextual_links_locations = {""}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\display\DisplayPluginBase
- class \Drupal\views\Plugin\views\display\Attachment
- class \Drupal\views\Plugin\views\display\DisplayPluginBase
- class \Drupal\views\Plugin\views\PluginBase
Expanded class hierarchy of Attachment
Related topics
2 string references to 'Attachment'
- views.view.glossary.yml in config/
views.view.glossary.yml - config/views.view.glossary.yml
- views.view.test_destroy.yml in tests/
views_test_config/ config/ views.view.test_destroy.yml - tests/views_test_config/config/views.view.test_destroy.yml
File
- lib/
Drupal/ views/ Plugin/ views/ display/ Attachment.php, line 30 - Definition of Drupal\views\Plugin\views\display\Attachment.
Namespace
Drupal\views\Plugin\views\displayView source
class Attachment extends DisplayPluginBase {
/**
* Whether the display allows the use of a pager or not.
*
* @var bool
*/
protected $usesPager = FALSE;
protected function defineOptions() {
$options = parent::defineOptions();
$options['displays'] = array(
'default' => array(),
);
$options['attachment_position'] = array(
'default' => 'before',
);
$options['inherit_arguments'] = array(
'default' => TRUE,
'bool' => TRUE,
);
$options['inherit_exposed_filters'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['inherit_pager'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['render_pager'] = array(
'default' => FALSE,
'bool' => TRUE,
);
return $options;
}
public function execute() {
return $this->view
->render($this->display['id']);
}
public function attachmentPositions($position = NULL) {
$positions = array(
'before' => t('Before'),
'after' => t('After'),
'both' => t('Both'),
);
if ($position) {
return $positions[$position];
}
return $positions;
}
/**
* Provide the summary for attachment options in the views UI.
*
* This output is returned as an array.
*/
public function optionsSummary(&$categories, &$options) {
// It is very important to call the parent function here:
parent::optionsSummary($categories, $options);
$categories['attachment'] = array(
'title' => t('Attachment settings'),
'column' => 'second',
'build' => array(
'#weight' => -10,
),
);
$displays = array_filter($this
->getOption('displays'));
if (count($displays) > 1) {
$attach_to = t('Multiple displays');
}
elseif (count($displays) == 1) {
$display = array_shift($displays);
if (!empty($this->view->display[$display])) {
$attach_to = check_plain($this->view->display[$display]['display_title']);
}
}
if (!isset($attach_to)) {
$attach_to = t('Not defined');
}
$options['displays'] = array(
'category' => 'attachment',
'title' => t('Attach to'),
'value' => $attach_to,
);
$options['attachment_position'] = array(
'category' => 'attachment',
'title' => t('Attachment position'),
'value' => $this
->attachmentPositions($this
->getOption('attachment_position')),
);
$options['inherit_arguments'] = array(
'category' => 'attachment',
'title' => t('Inherit contextual filters'),
'value' => $this
->getOption('inherit_arguments') ? t('Yes') : t('No'),
);
$options['inherit_exposed_filters'] = array(
'category' => 'attachment',
'title' => t('Inherit exposed filters'),
'value' => $this
->getOption('inherit_exposed_filters') ? t('Yes') : t('No'),
);
$options['inherit_pager'] = array(
'category' => 'pager',
'title' => t('Inherit pager'),
'value' => $this
->getOption('inherit_pager') ? t('Yes') : t('No'),
);
$options['render_pager'] = array(
'category' => 'pager',
'title' => t('Render pager'),
'value' => $this
->getOption('render_pager') ? t('Yes') : t('No'),
);
}
/**
* Provide the default form for setting options.
*/
public function buildOptionsForm(&$form, &$form_state) {
// It is very important to call the parent function here:
parent::buildOptionsForm($form, $form_state);
switch ($form_state['section']) {
case 'inherit_arguments':
$form['#title'] .= t('Inherit contextual filters');
$form['inherit_arguments'] = array(
'#type' => 'checkbox',
'#title' => t('Inherit'),
'#description' => t('Should this display inherit its contextual filter values from the parent display to which it is attached?'),
'#default_value' => $this
->getOption('inherit_arguments'),
);
break;
case 'inherit_exposed_filters':
$form['#title'] .= t('Inherit exposed filters');
$form['inherit_exposed_filters'] = array(
'#type' => 'checkbox',
'#title' => t('Inherit'),
'#description' => t('Should this display inherit its exposed filter values from the parent display to which it is attached?'),
'#default_value' => $this
->getOption('inherit_exposed_filters'),
);
break;
case 'inherit_pager':
$form['#title'] .= t('Inherit pager');
$form['inherit_pager'] = array(
'#type' => 'checkbox',
'#title' => t('Inherit'),
'#description' => t('Should this display inherit its paging values from the parent display to which it is attached?'),
'#default_value' => $this
->getOption('inherit_pager'),
);
break;
case 'render_pager':
$form['#title'] .= t('Render pager');
$form['render_pager'] = array(
'#type' => 'checkbox',
'#title' => t('Render'),
'#description' => t('Should this display render the pager values? This is only meaningful if inheriting a pager.'),
'#default_value' => $this
->getOption('render_pager'),
);
break;
case 'attachment_position':
$form['#title'] .= t('Position');
$form['attachment_position'] = array(
'#type' => 'radios',
'#description' => t('Attach before or after the parent display?'),
'#options' => $this
->attachmentPositions(),
'#default_value' => $this
->getOption('attachment_position'),
);
break;
case 'displays':
$form['#title'] .= t('Attach to');
$displays = array();
foreach ($this->view->display as $display_id => $display) {
if (!empty($this->view->displayHandlers[$display_id]) && $this->view->displayHandlers[$display_id]
->acceptAttachments()) {
$displays[$display_id] = $display['display_title'];
}
}
$form['displays'] = array(
'#type' => 'checkboxes',
'#description' => t('Select which display or displays this should attach to.'),
'#options' => $displays,
'#default_value' => $this
->getOption('displays'),
);
break;
}
}
/**
* Perform any necessary changes to the form values prior to storage.
* There is no need for this function to actually store the data.
*/
public function submitOptionsForm(&$form, &$form_state) {
// It is very important to call the parent function here:
parent::submitOptionsForm($form, $form_state);
switch ($form_state['section']) {
case 'inherit_arguments':
case 'inherit_pager':
case 'render_pager':
case 'inherit_exposed_filters':
case 'attachment_position':
case 'displays':
$this
->setOption($form_state['section'], $form_state['values'][$form_state['section']]);
break;
}
}
/**
* Attach to another view.
*/
public function attachTo($display_id) {
$displays = $this
->getOption('displays');
if (empty($displays[$display_id])) {
return;
}
if (!$this
->access()) {
return;
}
// Get a fresh view because our current one has a lot of stuff on it because it's
// already been executed.
$view = $this->view
->cloneView();
$args = $this
->getOption('inherit_arguments') ? $this->view->args : array();
$view
->setArguments($args);
$view
->setDisplay($this->display['id']);
if ($this
->getOption('inherit_pager')) {
$view->display_handler->usesPager = $this->view->display[$display_id]->handler
->usesPager();
$view->display_handler
->setOption('pager', $this->view->display[$display_id]->handler
->getOption('pager'));
}
$attachment = $view
->executeDisplay($this->display['id'], $args);
switch ($this
->getOption('attachment_position')) {
case 'before':
$this->view->attachment_before .= $attachment;
break;
case 'after':
$this->view->attachment_after .= $attachment;
break;
case 'both':
$this->view->attachment_before .= $attachment;
$this->view->attachment_after .= $attachment;
break;
}
$view
->destroy();
}
/**
* Attachment displays only use exposed widgets if
* they are set to inherit the exposed filter settings
* of their parent display.
*/
public function usesExposed() {
if (!empty($this->options['inherit_exposed_filters']) && parent::usesExposed()) {
return TRUE;
}
return FALSE;
}
/**
* If an attachment is set to inherit the exposed filter
* settings from its parent display, then don't render and
* display a second set of exposed filter widgets.
*/
public function displaysExposed() {
return $this->options['inherit_exposed_filters'] ? FALSE : TRUE;
}
public function renderPager() {
return $this
->usesPager() && $this
->getOption('render_pager');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Attachment:: |
protected | property |
Whether the display allows the use of a pager or not. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function | ||
Attachment:: |
public | function |
Attach to another view. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
Provide the default form for setting options. Overrides DisplayPluginBase:: |
|
Attachment:: |
protected | function |
Information about options for all kinds of purposes will be held here.
@code
'option_name' => array( Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
If an attachment is set to inherit the exposed filter
settings from its parent display, then don't render and
display a second set of exposed filter widgets. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
When used externally, this is how a view gets run and returns
data in the format required. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
Provide the summary for attachment options in the views UI. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
Not all display plugins will suppert pager rendering. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
Perform any necessary changes to the form values prior to storage.
There is no need for this function to actually store the data. Overrides DisplayPluginBase:: |
|
Attachment:: |
public | function |
Attachment displays only use exposed widgets if
they are set to inherit the exposed filter settings
of their parent display. Overrides DisplayPluginBase:: |
|
DisplayPluginBase:: |
property | Stores all available display extenders. | ||
DisplayPluginBase:: |
property | |||
DisplayPluginBase:: |
public | property | Stores the rendered output of the display. | |
DisplayPluginBase:: |
protected | property | An array of instantiated plugins used in this display. | |
DisplayPluginBase:: |
protected | property | Whether the display allows the use of AJAX or not. | 1 |
DisplayPluginBase:: |
protected | property | Whether the display allows attachments. | 4 |
DisplayPluginBase:: |
protected | property | Whether the display allows the use of a 'more' link or not. | |
DisplayPluginBase:: |
protected | property |
Overrides Drupal\views\Plugin\Plugin::$usesOptions. Overrides PluginBase:: |
|
DisplayPluginBase:: |
property |
The top object of a view. Overrides PluginBase:: |
||
DisplayPluginBase:: |
public | function | Determines whether this display can use attachments. | |
DisplayPluginBase:: |
public | function | Determine if the user has access to this display of the view. | |
DisplayPluginBase:: |
public | function | Static member function to list which sections are defaultable and what items each section contains. | 1 |
DisplayPluginBase:: |
public | function |
Clears a plugin. Overrides PluginBase:: |
|
DisplayPluginBase:: |
protected | function | Format a list of theme templates for output by the theme info helper. | |
DisplayPluginBase:: |
public | function | Returns to tokens for arguments. | |
DisplayPluginBase:: |
public | function | Provide some helpful text for the arguments. The result should contain of an array with | 1 |
DisplayPluginBase:: |
public | function | Retrieve a list of fields for the current display with the relationship associated if it exists. | |
DisplayPluginBase:: |
public | function | Get the handler object for a single handler. | |
DisplayPluginBase:: |
public | function | Get a full array of handlers for $type. This caches them. | |
DisplayPluginBase:: |
public | function | Check to see which display to use when creating links within a view using this display. | |
DisplayPluginBase:: |
public | function | Intelligently get an option either from this display or from the default display, if directed to do so. | |
DisplayPluginBase:: |
public | function | Provide some helpful text for pagers. | 1 |
DisplayPluginBase:: |
public | function | Return the base path to use for this display. | |
DisplayPluginBase:: |
public | function | Get the instance of a plugin, for example style or row. | |
DisplayPluginBase:: |
public | function | Provide the block system with any exposed widget blocks for this display. | |
DisplayPluginBase:: |
protected | function | Displays can require a certain type of style plugin. By default, they will be 'normal'. | 1 |
DisplayPluginBase:: |
public | function | ||
DisplayPluginBase:: |
public | function | Check to see if the display has a 'path' field. | 1 |
DisplayPluginBase:: |
public | function | If this display creates a block, implement one of these. | |
DisplayPluginBase:: |
public | function | If this display creates a page with a menu item, implement it here. | |
DisplayPluginBase:: |
public | function | 1 | |
DisplayPluginBase:: |
public | function | Whether the display is actually using AJAX or not. | |
DisplayPluginBase:: |
public | function | Determine if this display is the 'default' display which contains fallback settings | 1 |
DisplayPluginBase:: |
public | function | Determine if a given option is set to use the default display or the current display | |
DisplayPluginBase:: |
public | function | Whether the display is enabled. | |
DisplayPluginBase:: |
public | function | Check if the provided identifier is unique. | |
DisplayPluginBase:: |
public | function | Whether the display is using the 'more' link or not. | |
DisplayPluginBase:: |
public | function | Whether the display is using a pager or not. | |
DisplayPluginBase:: |
public | function | Because forms may be split up into sections, this provides an easy URL to exactly the right section. Don't override this. | |
DisplayPluginBase:: |
public | function | If override/revert was clicked, perform the proper toggle. | |
DisplayPluginBase:: |
public | function | Set an option and force it to be an override. | |
DisplayPluginBase:: |
public | function | Set up any variables on the view prior to execution. These are separated from execute because they are extremely common and unlikely to be overridden on an individual display. | |
DisplayPluginBase:: |
function | Fully render the display for the purposes of a live preview or some other AJAXy reason. | 2 | |
DisplayPluginBase:: |
public | function |
Inject anything into the query that the display handler needs. Overrides PluginBase:: |
|
DisplayPluginBase:: |
public | function | Render this display. | 1 |
DisplayPluginBase:: |
public | function | ||
DisplayPluginBase:: |
public | function | ||
DisplayPluginBase:: |
public | function | Not all display plugins will support filtering | |
DisplayPluginBase:: |
public | function | Render the footer of the view. | |
DisplayPluginBase:: |
public | function | Render the header of the view. | |
DisplayPluginBase:: |
public | function | Render the 'more' link | |
DisplayPluginBase:: |
public | function | Intelligently set an option either from this display or from the default display, if directed to do so. | |
DisplayPluginBase:: |
public | function | Flip the override setting for the given section. | |
DisplayPluginBase:: |
public | function | Does the display have groupby enabled? | |
DisplayPluginBase:: |
public | function | Should the enabled display more link be shown when no more items? | |
DisplayPluginBase:: |
public | function | Does the display have custom link text? | |
DisplayPluginBase:: |
public | function | Whether the display allows the use of AJAX or not. | 1 |
DisplayPluginBase:: |
public | function | Returns whether the display can use attachments. | 4 |
DisplayPluginBase:: |
public | function | Check to see if the display needs a breadcrumb | 1 |
DisplayPluginBase:: |
public | function | Check to see if the display can put the exposed formin a block. | |
DisplayPluginBase:: |
public | function | Determine if the display's style uses fields. | |
DisplayPluginBase:: |
public | function | Check to see if the display has some need to link to another display. | 1 |
DisplayPluginBase:: |
public | function | Whether the display allows the use of a 'more' link or not. | |
DisplayPluginBase:: |
public | function | Whether the display allows the use of a pager or not. | 2 |
DisplayPluginBase:: |
public | function |
Make sure the display and all associated handlers are valid. Overrides PluginBase:: |
1 |
DisplayPluginBase:: |
public | function |
Validate the options form. Overrides PluginBase:: |
2 |
DisplayPluginBase:: |
public | function | Render any special blocks provided for this display. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
public | property | Plugins's definition | |
PluginBase:: |
public | property | The display object this plugin is for. | |
PluginBase:: |
public | property | Options for this plugin will be held here. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public | function | Provide a list of additional theme functions for the theme information page | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Return the human readable name of the display. | |
PluginBase:: |
protected | function | ||
PluginBase:: |
public | function | Returns the summary of the settings in the display. | 6 |
PluginBase:: |
public | function | Provide a full list of possible theme templates used by this style. | 1 |
PluginBase:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
PluginBase:: |
public | function | Returns the usesOptions property. | 8 |
PluginBase:: |
public | function |
Constructs a Plugin object. Overrides PluginBase:: |
2 |