Commit a3a4347f authored by catch's avatar catch
Browse files

Issue #1870410 by damiankloip: Inject display plugin manager into DisplayBag class.

parent b272b9d4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\views; namespace Drupal\views;
use Drupal\Component\Plugin\PluginBag; use Drupal\Component\Plugin\PluginBag;
use Drupal\Component\Plugin\PluginManagerInterface;
/** /**
* A class which wraps the displays of a view so you can lazy-initialize them. * A class which wraps the displays of a view so you can lazy-initialize them.
...@@ -21,14 +22,24 @@ class DisplayBag extends PluginBag { ...@@ -21,14 +22,24 @@ class DisplayBag extends PluginBag {
*/ */
protected $view; protected $view;
/**
* The manager used to instantiate the plugins.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $manager;
/** /**
* Constructs a DisplayBag object. * Constructs a DisplayBag object.
* *
* @param \Drupal\views\ViewExecutable * @param \Drupal\views\ViewExecutable
* The view which has this displays attached. * 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) { public function __construct(ViewExecutable $view, PluginManagerInterface $manager) {
$this->view = $view; $this->view = $view;
$this->manager = $manager;
$this->initializePlugin('default'); $this->initializePlugin('default');
...@@ -66,11 +77,11 @@ protected function initializePlugin($display_id) { ...@@ -66,11 +77,11 @@ protected function initializePlugin($display_id) {
// Retrieve and initialize the new display handler with data. // Retrieve and initialize the new display handler with data.
$display = &$this->view->storage->getDisplay($display_id); $display = &$this->view->storage->getDisplay($display_id);
$this->pluginInstances[$display_id] = drupal_container()->get("plugin.manager.views.display")->createInstance($display['display_plugin']); $this->pluginInstances[$display_id] = $this->manager->createInstance($display['display_plugin']);
if (empty($this->pluginInstances[$display_id])) { if (empty($this->pluginInstances[$display_id])) {
// Provide a 'default' handler as an emergency. This won't work well but // Provide a 'default' handler as an emergency. This won't work well but
// it will keep things from crashing. // it will keep things from crashing.
$this->pluginInstances[$display_id] = drupal_container()->get("plugin.manager.views.display")->createInstance('default'); $this->pluginInstances[$display_id] = $this->manager->createInstance('default');
} }
$this->pluginInstances[$display_id]->initDisplay($this->view, $display); $this->pluginInstances[$display_id]->initDisplay($this->view, $display);
......
...@@ -597,7 +597,7 @@ public function initDisplay() { ...@@ -597,7 +597,7 @@ public function initDisplay() {
} }
// Initialize the display cache array. // Initialize the display cache array.
$this->displayHandlers = new DisplayBag($this); $this->displayHandlers = new DisplayBag($this, drupal_container()->get('plugin.manager.views.display'));
$this->current_display = 'default'; $this->current_display = 'default';
$this->display_handler = $this->displayHandlers['default']; $this->display_handler = $this->displayHandlers['default'];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment