diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/argument_default/Node.php b/core/modules/node/lib/Drupal/node/Plugin/views/argument_default/Node.php index c42b8cd..f232cea 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/argument_default/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/argument_default/Node.php @@ -9,8 +9,6 @@ use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; use Drupal\node\NodeInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; /** * Default argument plugin to extract a node. @@ -25,48 +23,12 @@ class Node extends ArgumentDefaultPluginBase { /** - * The request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** - * Constructs a new Node instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->request = $request; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('request') - ); - } - - /** * {@inheritdoc} */ public function getArgument() { - if (($node = $this->request->attributes->get('node')) && $node instanceof NodeInterface) { + if (($node = $this->view->getRequest()->attributes->get('node')) && $node instanceof NodeInterface) { return $node->id(); } } + } diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php index 263e441..12e6be5 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php @@ -14,7 +14,6 @@ use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\PathPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouteCollection; @@ -80,13 +79,6 @@ class RestExport extends PathPluginBase { protected $contentNegotiation; /** - * The request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** * Constructs a Drupal\rest\Plugin\ResourceBase object. * * @param array $configuration @@ -103,13 +95,10 @@ class RestExport extends PathPluginBase { * The form error helper. * @param \Drupal\Core\ContentNegotiation $content_negotiation * The content negotiation library. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, FormErrorInterface $form_error, ContentNegotiation $content_negotiation, Request $request) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, FormErrorInterface $form_error, ContentNegotiation $content_negotiation) { parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state, $form_error); $this->contentNegotiation = $content_negotiation; - $this->request = $request; } /** @@ -123,8 +112,7 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('router.route_provider'), $container->get('state'), $container->get('form_validator'), - $container->get('content_negotiation'), - $container->get('request') + $container->get('content_negotiation') ); } @@ -134,7 +122,7 @@ public static function create(ContainerInterface $container, array $configuratio public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) { parent::initDisplay($view, $display, $options); - $request_content_type = $this->contentNegotiation->getContentType($this->request); + $request_content_type = $this->contentNegotiation->getContentType($this->view->getRequest()); // Only use the requested content type if it's not 'html'. If it is then // default to 'json' to aid debugging. // @todo Remove the need for this when we have better content negotiation. @@ -142,7 +130,7 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio $this->setContentType($request_content_type); } - $this->setMimeType($this->request->getMimeType($this->contentType)); + $this->setMimeType($this->view->getRequest()->getMimeType($this->contentType)); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php index 33b35a8..cf25c15 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php @@ -25,42 +25,6 @@ class Tid extends ArgumentDefaultPluginBase { /** - * The request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** - * Constructs a new Tid instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->request = $request; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('request') - ); - } - - /** * Overrides \Drupal\views\Plugin\views\Plugin\views\PluginBase::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -166,7 +130,7 @@ public function getArgument() { // Load default argument from node. if (!empty($this->options['node'])) { // Just check, if a node could be detected. - if (($node = $this->request->attributes->has('node')) && $node instanceof NodeInterface) { + if (($node = $this->view->getRequest()->attributes->has('node')) && $node instanceof NodeInterface) { $taxonomy = array(); foreach ($node->getFieldDefinitions() as $field) { if ($field->getType() == 'taxonomy_term_reference') { diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/argument_default/User.php b/core/modules/user/lib/Drupal/user/Plugin/views/argument_default/User.php index dc8812d..fad8743 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/argument_default/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/argument_default/User.php @@ -24,43 +24,6 @@ class User extends ArgumentDefaultPluginBase { /** - * The request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** - * Constructs a default argument User object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->request = $request; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('request') - ); - } - - /** * {@inheritdoc} */ protected function defineOptions() { @@ -87,16 +50,16 @@ public function buildOptionsForm(&$form, &$form_state) { public function getArgument() { // If there is a user object in the current route. - if ($this->request->attributes->has('user')) { - $user = $this->request->attributes->get('user'); + if ($this->view->getRequest()->attributes->has('user')) { + $user = $this->view->getRequest()->attributes->get('user'); if ($user instanceof UserInterface) { return $user->id(); } } // If option to use node author; and node in current route. - if (!empty($this->options['user']) && $this->request->attributes->has('node')) { - $node = $this->request->attributes->get('node'); + if (!empty($this->options['user']) && $this->view->getRequest()->attributes->has('node')) { + $node = $this->view->getRequest()->attributes->get('node'); if ($node instanceof NodeInterface) { return $node->getOwnerId(); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument/Date.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument/Date.php index b52e84f..67c0055 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/argument/Date.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument/Date.php @@ -44,45 +44,9 @@ class Date extends Formula { */ protected $argFormat = 'Y-m-d'; - /** - * The request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - var $option_name = 'default_argument_date'; /** - * Constructs a new Date instance. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->request = $request; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('request') - ); - } - - /** * Add an option to set the default value to the current date. */ public function defaultArgumentForm(&$form, &$form_state) { @@ -101,7 +65,7 @@ public function getDefaultArgument($raw = FALSE) { return date($this->argFormat, REQUEST_TIME); } elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) { - $node = $this->request->attributes->get('node'); + $node = $this->view->getRequest()->attributes->get('node'); if (!($node instanceof NodeInterface)) { return parent::getDefaultArgument(); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/Raw.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/Raw.php index 3f144ae..e7007fa 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/Raw.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/Raw.php @@ -24,13 +24,6 @@ class Raw extends ArgumentDefaultPluginBase { /** - * The request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** * The alias manager. * * @var \Drupal\Core\Path\AliasManagerInterface @@ -46,15 +39,12 @@ class Raw extends ArgumentDefaultPluginBase { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager * The alias manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, AliasManagerInterface $alias_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, AliasManagerInterface $alias_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->request = $request; $this->aliasManager = $alias_manager; } @@ -66,7 +56,6 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('request'), $container->get('path.alias_manager.cached') ); } @@ -99,7 +88,7 @@ public function buildOptionsForm(&$form, &$form_state) { } public function getArgument() { - $path = $this->request->attributes->get('_system_path'); + $path = $this->view->getRequest()->attributes->get('_system_path'); if ($this->options['use_alias']) { $path = $this->aliasManager->getAliasByPath($path); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php index 4f2503c..046c3a5 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php @@ -297,10 +297,9 @@ public function generateResultsKey() { 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->id, 'base_url' => $GLOBALS['base_url'], ); - $request = \Drupal::request(); foreach (array('exposed_info', 'page', 'sort', 'order', 'items_per_page', 'offset') as $key) { - if ($request->query->has($key)) { - $key_data[$key] = $request->query->get($key); + if ($this->view->getRequest()->query->has($key)) { + $key_data[$key] = $this->view->getRequest()->query->get($key); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 750546f..c5634e7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -893,8 +893,7 @@ public function getHandlers($type) { // @todo Remove dependency on Request object // https://drupal.org/node/2059003. try { - $request = \Drupal::request(); - if ($request->request->get('form_id') && isset($this->view->temporary_options[$type][$id])) { + if ($this->view->getRequest()->request->get('form_id') && isset($this->view->temporary_options[$type][$id])) { $info = $this->view->temporary_options[$type][$id]; } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php index 482a032..5eb5765 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php @@ -1485,7 +1485,7 @@ public function getRenderTokens($item) { } // Get flattened set of tokens for any array depth in query parameters. - $tokens += $this->getTokenValuesRecursive(\Drupal::request()->query->all()); + $tokens += $this->getTokenValuesRecursive($this->view->getRequest()->query->all()); // Now add replacements for our fields. foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/pager/SqlBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/pager/SqlBase.php index a0c1c3d..7aeb69e 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/pager/SqlBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/pager/SqlBase.php @@ -211,7 +211,7 @@ public function validateOptionsForm(&$form, &$form_state) { public function query() { if ($this->itemsPerPageExposed()) { - $query = \Drupal::request()->query; + $query = $this->view->getRequest()->query; $items_per_page = $query->get('items_per_page'); if ($items_per_page > 0) { $this->options['items_per_page'] = $items_per_page; @@ -221,7 +221,7 @@ public function query() { } } if ($this->isOffsetExposed()) { - $query = \Drupal::request()->query; + $query = $this->view->getRequest()->query; $offset = $query->get('offset'); if (isset($offset) && $offset >= 0) { $this->options['offset'] = $offset; @@ -265,7 +265,7 @@ public function setCurrentPage($number = NULL) { // Fill in missing values in the global page array, in case the global page // array hasn't been initialized before. - $page = \Drupal::request()->query->get('page'); + $page = $this->view->getRequest()->query->get('page'); $page = isset($page) ? explode(',', $page) : array(); for ($i = 0; $i <= $this->options['id'] || $i < count($pager_page_array); $i++) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php index a8225b3..789857e 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php @@ -60,29 +60,6 @@ class Table extends StylePluginBase { */ public $order; - /** - * Contains the current request object. - * - * @var \Symfony\Component\HttpFoundation\Request - */ - protected $request; - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($configuration, $plugin_id, $plugin_definition, $container->get('request')); - } - - /** - * Constructs a Table object. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->request = $request; - } - protected function defineOptions() { $options = parent::defineOptions(); @@ -104,7 +81,7 @@ protected function defineOptions() { * {@inheritdoc} */ public function buildSort() { - $order = $this->request->query->get('order'); + $order = $this->view->getRequest()->query->get('order'); if (!isset($order) && ($this->options['default'] == -1 || empty($this->view->field[$this->options['default']]))) { return TRUE; } @@ -122,7 +99,7 @@ public function buildSort() { * Add our actual sort criteria */ public function buildSortPost() { - $query = $this->request->query; + $query = $this->view->getRequest()->query; $order = $query->get('order'); if (!isset($order)) { // check for a 'default' clicksort. If there isn't one, exit gracefully. diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_default/RawTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_default/RawTest.php index 397cb36..a6437a2 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_default/RawTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_default/RawTest.php @@ -40,12 +40,15 @@ public function testGetArgument() { ->getMock(); $request = new Request(array(), array(), array('_system_path' => 'test/example')); + $view->expects($this->any()) + ->method('getRequest') + ->will($this->returnValue($request)); $alias_manager = $this->getMock('Drupal\Core\Path\AliasManagerInterface'); $alias_manager->expects($this->never()) ->method('getAliasByPath'); // Don't use aliases. - $raw = new Raw(array(), 'raw', array(), $request, $alias_manager); + $raw = new Raw(array(), 'raw', array(), $alias_manager); $options = array( 'use_alias' => FALSE, 'index' => 0, @@ -53,7 +56,7 @@ public function testGetArgument() { $raw->init($view, $display_plugin, $options); $this->assertEquals('test', $raw->getArgument()); - $raw = new Raw(array(), 'raw', array(), $request, $alias_manager); + $raw = new Raw(array(), 'raw', array(), $alias_manager); $options = array( 'use_alias' => FALSE, 'index' => 1, @@ -68,7 +71,7 @@ public function testGetArgument() { ->with($this->equalTo('test/example')) ->will($this->returnValue('other/example')); - $raw = new Raw(array(), 'raw', array(), $request, $alias_manager); + $raw = new Raw(array(), 'raw', array(), $alias_manager); $options = array( 'use_alias' => TRUE, 'index' => 0, @@ -76,7 +79,7 @@ public function testGetArgument() { $raw->init($view, $display_plugin, $options); $this->assertEquals('other', $raw->getArgument()); - $raw = new Raw(array(), 'raw', array(), $request, $alias_manager); + $raw = new Raw(array(), 'raw', array(), $alias_manager); $options = array( 'use_alias' => TRUE, 'index' => 1, diff --git a/core/modules/views/tests/Drupal/views/Tests/ViewExecutableFactoryTest.php b/core/modules/views/tests/Drupal/views/Tests/ViewExecutableFactoryTest.php index 931d484..f4cc82b 100644 --- a/core/modules/views/tests/Drupal/views/Tests/ViewExecutableFactoryTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/ViewExecutableFactoryTest.php @@ -9,6 +9,8 @@ use Drupal\Tests\UnitTestCase; use Drupal\views\ViewExecutableFactory; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; /** * Tests the ViewExecutableFactory class. @@ -27,7 +29,7 @@ class ViewExecutableFactoryTest extends UnitTestCase { /** * The mock request stack object. * - * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit_Framework_MockObject_MockObject + * @var \Symfony\Component\HttpFoundation\RequestStack */ protected $requestStack; @@ -63,7 +65,7 @@ public function setUp() { parent::setUp(); $this->user = $this->getMock('Drupal\Core\Session\AccountInterface'); - $this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + $this->requestStack = new RequestStack(); $this->view = $this->getMock('Drupal\views\ViewStorageInterface'); $this->viewExecutableFactory = new ViewExecutableFactory($this->user, $this->requestStack); } @@ -74,21 +76,10 @@ public function setUp() { * @covers ::get */ public function testGet() { - $request_1 = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') - ->disableOriginalConstructor() - ->getMock(); - - $request_2 = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') - ->disableOriginalConstructor() - ->getMock(); - - $this->requestStack->expects($this->at(0)) - ->method('getCurrentRequest') - ->will($this->returnValue($request_1)); - $this->requestStack->expects($this->at(1)) - ->method('getCurrentRequest') - ->will($this->returnValue($request_2)); + $request_1 = new Request(); + $request_2 = new Request(); + $this->requestStack->push($request_1); $executable = $this->viewExecutableFactory->get($this->view); @@ -98,6 +89,7 @@ public function testGet() { // Call get() again to ensure a new executable is created with the other // request object. + $this->requestStack->push($request_2); $executable = $this->viewExecutableFactory->get($this->view); $this->assertInstanceOf('Drupal\views\ViewExecutable', $executable);