Commit 419d1d9b authored by catch's avatar catch

Issue #1945670 by dawehner, damiankloip: Load plugin instances implicit on the ViewExecutable.

parent 6a342835
......@@ -17,6 +17,8 @@
use Drupal\views\Plugin\views\style\Grid;
use Drupal\views\Plugin\views\row\Fields;
use Drupal\views\Plugin\views\query\Sql;
use Drupal\views\Plugin\views\pager\PagerPluginBase;
use Drupal\views\Plugin\views\query\QueryPluginBase;
/**
* Tests the ViewExecutable class.
......@@ -141,6 +143,29 @@ public function testInitMethods() {
$this->assertTrue($view->query instanceof Sql, 'Make sure a reference to the query is set');
$this->assertEqual(spl_object_hash($view->query->view), $view_hash);
$this->assertEqual(spl_object_hash($view->query->displayHandler), $display_hash);
$view->destroy();
// Test the plugin get methods.
$display_plugin = $view->getDisplay();
$this->assertTrue($display_plugin instanceof DefaultDisplay, 'An instance of DefaultDisplay was returned.');
$this->assertTrue($view->display_handler instanceof DefaultDisplay, 'The display_handler property has been set.');
$this->assertIdentical($display_plugin, $view->getDisplay(), 'The same display plugin instance was returned.');
$style_plugin = $view->getStyle();
$this->assertTrue($style_plugin instanceof DefaultStyle, 'An instance of DefaultStyle was returned.');
$this->assertTrue($view->style_plugin instanceof DefaultStyle, 'The style_plugin property has been set.');
$this->assertIdentical($style_plugin, $view->getStyle(), 'The same style plugin instance was returned.');
$pager_plugin = $view->getPager();
$this->assertTrue($pager_plugin instanceof PagerPluginBase, 'An instance of PagerPluginBase was returned.');
$this->assertTrue($view->pager instanceof PagerPluginBase, 'The pager property has been set.');
$this->assertIdentical($pager_plugin, $view->getPager(), 'The same pager plugin instance was returned.');
$query_plugin = $view->getQuery();
$this->assertTrue($query_plugin instanceof QueryPluginBase, 'An instance of QueryPluginBase was returned.');
$this->assertTrue($view->query instanceof QueryPluginBase, 'The query property has been set.');
$this->assertIdentical($query_plugin, $view->getQuery(), 'The same query plugin instance was returned.');
}
/**
......
......@@ -8,9 +8,10 @@
namespace Drupal\views;
use Drupal;
use Symfony\Component\HttpFoundation\Response;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewStorageInterface;
use Drupal\Component\Utility\Tags;
use Symfony\Component\HttpFoundation\Response;
/**
* @defgroup views_objects Objects that represent a View or part of a view
......@@ -635,6 +636,19 @@ public function chooseDisplay($displays) {
return 'default';
}
/**
* Gets the current display plugin.
*
* @return \Drupal\views\Plugin\views\display\DisplayPluginBase
*/
public function getDisplay() {
if (!isset($this->display_handler)) {
$this->initDisplay();
}
return $this->display_handler;
}
/**
* Sets the current display.
*
......@@ -687,6 +701,19 @@ public function setDisplay($display_id = NULL) {
return FALSE;
}
/**
* Gets the current style plugin.
*
* @return \Drupal\views\Plugin\views\style\StylePluginBase
*/
public function getStyle() {
if (!isset($this->style_plugin)) {
$this->initStyle();
}
return $this->style_plugin;
}
/**
* Find and initialize the style plugin.
*
......@@ -720,6 +747,19 @@ public function initHandlers() {
}
}
/**
* Get the current pager plugin.
*
* @return \Drupal\views\Plugin\views\pager\PagerPluginBase
*/
public function getPager() {
if (!isset($this->pager)) {
$this->initPager();
}
return $this->pager;
}
/**
* Initialize the pager
*
......@@ -934,6 +974,19 @@ protected function _buildArguments() {
return $status;
}
/**
* Gets the current query plugin.
*
* @return \Drupal\views\Plugin\views\query\QueryPluginBase
*/
public function getQuery() {
if (!isset($this->query)) {
$this->initQuery();
}
return $this->query;
}
/**
* Do some common building initialization.
*/
......
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