class DisplayPluginCollection in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/src/DisplayPluginCollection.php \Drupal\views\DisplayPluginCollection
A class which wraps the displays of a view so you can lazy-initialize them.
Hierarchy
- class \Drupal\Component\Plugin\LazyPluginCollection implements \Drupal\Component\Plugin\IteratorAggregate, \Drupal\Component\Plugin\Countable
- class \Drupal\Core\Plugin\DefaultLazyPluginCollection uses DependencySerializationTrait
- class \Drupal\views\DisplayPluginCollection
- class \Drupal\Core\Plugin\DefaultLazyPluginCollection uses DependencySerializationTrait
Expanded class hierarchy of DisplayPluginCollection
1 file declares its use of DisplayPluginCollection
- ViewExecutableTest.php in core/
modules/ views/ tests/ src/ Kernel/ ViewExecutableTest.php
File
- core/
modules/ views/ src/ DisplayPluginCollection.php, line 12
Namespace
Drupal\viewsView source
class DisplayPluginCollection extends DefaultLazyPluginCollection {
/**
* Stores a reference to the view which has this displays attached.
*
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* {@inheritdoc}
*/
protected $pluginKey = 'display_plugin';
/**
* Constructs a DisplayPluginCollection object.
*
* @param \Drupal\views\ViewExecutable $view
* The view which has this displays attached.
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
* The manager to be used for instantiating plugins.
*/
public function __construct(ViewExecutable $view, PluginManagerInterface $manager) {
parent::__construct($manager, $view->storage
->get('display'));
$this->view = $view;
$this
->initializePlugin('default');
}
/**
* Destructs a DisplayPluginCollection object.
*/
public function __destruct() {
$this
->clear();
}
/**
* {@inheritdoc}
*
* @return \Drupal\views\Plugin\views\display\DisplayPluginBase
*/
public function &get($instance_id) {
return parent::get($instance_id);
}
/**
* {@inheritdoc}
*/
public function clear() {
foreach (array_filter($this->pluginInstances) as $display) {
$display
->destroy();
}
parent::clear();
}
/**
* {@inheritdoc}
*/
protected function initializePlugin($display_id) {
// Retrieve and initialize the new display handler with data.
$display =& $this->view->storage
->getDisplay($display_id);
try {
$this->configurations[$display_id] = $display;
parent::initializePlugin($display_id);
} catch (PluginException $e) {
$message = $e
->getMessage();
\Drupal::messenger()
->addWarning(t('@message', [
'@message' => $message,
]));
}
// If no plugin instance has been created, return NULL.
if (empty($this->pluginInstances[$display_id])) {
return NULL;
}
$this->pluginInstances[$display_id]
->initDisplay($this->view, $display);
// If this is not the default display handler, let it know which is since
// it may well use some data from the default.
if ($display_id != 'default') {
$this->pluginInstances[$display_id]->default_display = $this->pluginInstances['default'];
}
}
/**
* {@inheritdoc}
*/
public function remove($instance_id) {
$this
->get($instance_id)
->remove();
parent::remove($instance_id);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultLazyPluginCollection:: |
protected | property | The initial configuration for each plugin in the collection. | |
DefaultLazyPluginCollection:: |
protected | property | The manager used to instantiate the plugins. | |
DefaultLazyPluginCollection:: |
protected | property | The original order of the instances. | |
DefaultLazyPluginCollection:: |
public | function |
Adds an instance ID to the available instance IDs. Overrides LazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
public | function |
Gets the current configuration of all plugins in this collection. Overrides LazyPluginCollection:: |
2 |
DefaultLazyPluginCollection:: |
public | function |
Removes an instance ID. Overrides LazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
public | function |
Sets the configuration for all plugins in this collection. Overrides LazyPluginCollection:: |
|
DefaultLazyPluginCollection:: |
public | function | Updates the configuration for a plugin instance. | |
DefaultLazyPluginCollection:: |
public | function | Sorts all plugin instances in this collection. | 1 |
DefaultLazyPluginCollection:: |
public | function | Provides uasort() callback to sort plugins. | 2 |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
DisplayPluginCollection:: |
protected | property |
The key within the plugin configuration that contains the plugin ID. Overrides DefaultLazyPluginCollection:: |
|
DisplayPluginCollection:: |
protected | property | Stores a reference to the view which has this displays attached. | |
DisplayPluginCollection:: |
public | function |
Clears all instantiated plugins. Overrides LazyPluginCollection:: |
|
DisplayPluginCollection:: |
public | function |
Overrides LazyPluginCollection:: |
|
DisplayPluginCollection:: |
protected | function |
Initializes and stores a plugin. Overrides DefaultLazyPluginCollection:: |
|
DisplayPluginCollection:: |
public | function |
Removes an initialized plugin. Overrides LazyPluginCollection:: |
|
DisplayPluginCollection:: |
public | function |
Constructs a DisplayPluginCollection object. Overrides DefaultLazyPluginCollection:: |
|
DisplayPluginCollection:: |
public | function | Destructs a DisplayPluginCollection object. | |
LazyPluginCollection:: |
protected | property | Stores the IDs of all potential plugin instances. | |
LazyPluginCollection:: |
protected | property | Stores all instantiated plugins. | |
LazyPluginCollection:: |
public | function | ||
LazyPluginCollection:: |
public | function | Gets all instance IDs. | |
LazyPluginCollection:: |
public | function | ||
LazyPluginCollection:: |
public | function | Determines if a plugin instance exists. | |
LazyPluginCollection:: |
public | function | Stores an initialized plugin. |