3 namespace Drupal\views;
5 use Drupal\Component\Plugin\Exception\PluginException;
6 use Drupal\Component\Plugin\PluginManagerInterface;
7 use Drupal\Core\Plugin\DefaultLazyPluginCollection;
10 * A class which wraps the displays of a view so you can lazy-initialize them.
12 class DisplayPluginCollection extends DefaultLazyPluginCollection {
15 * Stores a reference to the view which has this displays attached.
17 * @var \Drupal\views\ViewExecutable
24 protected $pluginKey = 'display_plugin';
27 * Constructs a DisplayPluginCollection object.
29 * @param \Drupal\views\ViewExecutable $view
30 * The view which has this displays attached.
31 * @param \Drupal\Component\Plugin\PluginManagerInterface $manager
32 * The manager to be used for instantiating plugins.
34 public function __construct(ViewExecutable $view, PluginManagerInterface $manager) {
35 parent::__construct($manager, $view->storage->get('display'));
38 $this->initializePlugin('default');
42 * Destructs a DisplayPluginCollection object.
44 public function __destruct() {
51 * @return \Drupal\views\Plugin\views\display\DisplayPluginBase
53 public function &get($instance_id) {
54 return parent::get($instance_id);
60 public function clear() {
61 foreach (array_filter($this->pluginInstances) as $display) {
71 protected function initializePlugin($display_id) {
72 // Retrieve and initialize the new display handler with data.
73 $display = &$this->view->storage->getDisplay($display_id);
76 $this->configurations[$display_id] = $display;
77 parent::initializePlugin($display_id);
79 // Catch any plugin exceptions that are thrown. So we can fail nicely if a
80 // display plugin isn't found.
81 catch (PluginException $e) {
82 $message = $e->getMessage();
83 drupal_set_message(t('@message', ['@message' => $message]), 'warning');
86 // If no plugin instance has been created, return NULL.
87 if (empty($this->pluginInstances[$display_id])) {
91 $this->pluginInstances[$display_id]->initDisplay($this->view, $display);
92 // If this is not the default display handler, let it know which is since
93 // it may well use some data from the default.
94 if ($display_id != 'default') {
95 $this->pluginInstances[$display_id]->default_display = $this->pluginInstances['default'];
102 public function remove($instance_id) {
103 $this->get($instance_id)->remove();
105 parent::remove($instance_id);