diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php index 2caeffc58a72bbd5c68c224e684eceddc6c1733b..6ef4a52063a2524d639f23fc44c43a3c138ae4dc 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Plugin\views\field; use Drupal\comment\CommentInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\views\ResultRow; /** @@ -19,9 +20,12 @@ */ class LinkApprove extends Link { - public function access() { + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { //needs permission to administer comments in general - return user_access('administer comments'); + return $account->hasPermission('administer comments'); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php index eed6baed437c27a2a0afa11709576a7cabd7e33f..c225580a947685ccd77fa2291fb0ef3fdc8ceba5 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\Core\Session\AccountInterface; use Drupal\views\ResultRow; /** @@ -18,9 +19,12 @@ */ class LinkDelete extends Link { - public function access() { + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { //needs permission to administer comments in general - return user_access('administer comments'); + return $account->hasPermission('administer comments'); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php index b9fd19e64b9829b78d1007af7e4f9144c378d6bd..aefb38d476406dbbf53cbee194dcb8e642fbe365 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\Core\Session\AccountInterface; use Drupal\views\ResultRow; /** @@ -18,9 +19,12 @@ */ class LinkReply extends Link { - public function access() { + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { //check for permission to reply to comments - return user_access('post comments'); + return $account->hasPermission('post comments'); } /** diff --git a/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php b/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php index 86d6f63d6e47bc88b36585423b5024205c7d2cd9..b6f84aeeb4ebc6e03d21d53345e9d319a8b75040 100644 --- a/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php +++ b/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php @@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessManager; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\user\Plugin\views\field\Link; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -93,7 +94,7 @@ public function buildOptionsForm(&$form, &$form_state) { /** * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { // The access logic is implemented per row. return TRUE; } diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 2a3b8fd53c93ab1007d555a36e335debfbd7dbba..6c6b35083c5f558e595ebe526405a8fae2422b48 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -17,6 +17,7 @@ use Drupal\Core\Field\FormatterPluginManager; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Views; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -167,15 +168,12 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o } /** - * Check whether current user has access to this handler. - * - * @return bool - * Return TRUE if the user has access to view this field. + * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { $base_table = $this->get_base_table(); $access_controller = $this->entityManager->getAccessController($this->definition['entity_tables'][$base_table]); - return $access_controller->fieldAccess('view', $this->field_info); + return $access_controller->fieldAccess('view', $this->field_info, $account); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php index 71bb22905e014cfab0e9ad0d89343d0076bc3e8f..80681f1fd7ce7ce480ee76316532d78c66ef62ff 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php @@ -7,6 +7,7 @@ namespace Drupal\node\Plugin\views\field; +use Drupal\Core\Session\AccountInterface; use Drupal\node\Plugin\views\field\Link; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; @@ -30,8 +31,11 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o $this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid'); } - public function access() { - return user_access('view revisions') || user_access('administer nodes'); + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { + return $account->hasPermission('view revisions') || $account->hasPermission('administer nodes'); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php index 899aa83887ac7c67317e662ec14c22b4ea0ba86c..af0bc8a614ce3a281dab653778735f411e178f24 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php @@ -7,6 +7,7 @@ namespace Drupal\node\Plugin\views\field; +use Drupal\Core\Session\AccountInterface; use Drupal\node\Plugin\views\field\RevisionLink; use Drupal\views\ResultRow; @@ -19,8 +20,11 @@ */ class RevisionLinkDelete extends RevisionLink { - public function access() { - return user_access('delete revisions') || user_access('administer nodes'); + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { + return $account->hasPermission('delete revisions') || $account->hasPermission('administer nodes'); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php index d45e476efa9c339c59dd6170cb8eef462328b347..bb97d1f39f4d919d726b66cb156afa192cfb4d88 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php @@ -7,6 +7,7 @@ namespace Drupal\node\Plugin\views\field; +use Drupal\Core\Session\AccountInterface; use Drupal\node\Plugin\views\field\RevisionLink; use Drupal\views\ResultRow; @@ -19,8 +20,11 @@ */ class RevisionLinkRevert extends RevisionLink { - public function access() { - return user_access('revert revisions') || user_access('administer nodes'); + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { + return $account->hasPermission('revert revisions') || $account->hasPermission('administer nodes'); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php b/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php index 09e7c7321b9b7eed6858b0cfbfc22dc81bce1126..3d6e4cc5442fc2acbd5c9819d0e2d253a98e3b48 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/filter/Access.php @@ -28,7 +28,7 @@ public function canExpose() { * See _node_access_where_sql() for a non-views query based implementation. */ public function query() { - if (!user_access('administer nodes')) { + if (!$this->view->getUser()->hasPermission('administer nodes')) { $table = $this->ensureMyTable(); $grants = db_or(); foreach (node_access_grants('view') as $realm => $gids) { diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php b/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php index 5dcc43dc587c3cda4b47716620b00ead2f51fd97..2251a6e4c5302f9f34a93565ffff3dd1dd58ccb7 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php @@ -33,7 +33,7 @@ class Permission extends AccessPluginBase { * {@inheritdoc} */ public function access(AccountInterface $account) { - return user_access($this->options['perm'], $account) || user_access('access all views', $account); + return $account->hasPermission($this->options['perm']) || $account->hasPermission('access all views'); } /** diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php b/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php index aa4f1ce93fef9c9a553750964ecc8c00c8f61790..a50ac39028b6092e22a1c6e23700b09d8cfab5c1 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php @@ -33,7 +33,7 @@ class Role extends AccessPluginBase { * {@inheritdoc} */ public function access(AccountInterface $account) { - return user_access('access all views', $account) || array_intersect(array_filter($this->options['role']), $account->getRoles()); + return $account->hasPermission('access all views') || array_intersect(array_filter($this->options['role']), $account->getRoles()); } /** diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php index 6a9af10a4c6f7a2ca2347bfa07a7fd76e0c2a5d2..924bf5627dd1cbb5b3958d47979bf4a9363f9494 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php @@ -24,7 +24,7 @@ class Language extends User { protected function renderLink($data, ResultRow $values) { if (!empty($this->options['link_to_user'])) { $uid = $this->getValue($values, 'uid'); - if (user_access('access user profiles') && $uid) { + if ($this->view->getUser()->hasPermission('access user profiles') && $uid) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = 'user/' . $uid; } diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php index 2d3954243d2aace1c8552846f6c89cc6ce5c7d97..5c75d850e11257281af5ff200bebad6c80181cc7 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php @@ -7,6 +7,7 @@ namespace Drupal\user\Plugin\views\field; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; @@ -53,9 +54,11 @@ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); } - // An example of field level access control. - public function access() { - return user_access('administer users') || user_access('access user profiles'); + /** + * {@inheritdoc} + */ + public function access(AccountInterface $account) { + return $account->hasPermission('administer users') || $account->hasPermission('access user profiles'); } public function query() { diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php index 7077685e3997a3ed96257c4d274e4d44824a7f32..c40f20469a472c21e599c55b7f9450e7a4d34bca 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php @@ -63,7 +63,7 @@ public function buildOptionsForm(&$form, &$form_state) { * Returns a string for the link text. */ protected function renderLink($data, ResultRow $values) { - if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($entity = $this->getEntity($values)) && $data !== NULL && $data !== '') { + if (!empty($this->options['link_to_user']) && $this->view->getUser()->hasPermission('access user profiles') && ($entity = $this->getEntity($values)) && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; $uri = $entity->uri(); $this->options['alter']['path'] = $uri['path']; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index 0a51c881b9f942c5f3697550186c912fe7dedfa9..9590e1caa0620aa84bff16e695779eb1810e9a2b 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Url; use Drupal\Component\Utility\Xss; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\ViewExecutable; @@ -461,14 +462,15 @@ public function showExposeForm(&$form, &$form_state) { /** * Check whether current user has access to this handler. * + * @param AccountInterface $account * @return boolean */ - public function access() { + public function access(AccountInterface $account) { if (isset($this->definition['access callback']) && function_exists($this->definition['access callback'])) { if (isset($this->definition['access arguments']) && is_array($this->definition['access arguments'])) { - return call_user_func_array($this->definition['access callback'], $this->definition['access arguments']); + return call_user_func_array($this->definition['access callback'], array($account) + $this->definition['access arguments']); } - return $this->definition['access callback'](); + return $this->definition['access callback']($account); } return TRUE; 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 81a778dd091435d1b142b9725796ad4c2217db3b..1656fca0cc237613b4bd1b29230cff8880a92ecb 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 @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Language\Language; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\Theme\Registry; use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\ViewExecutable; @@ -874,6 +875,8 @@ public function &getHandler($type, $id) { /** * Get a full array of handlers for $type. This caches them. + * + * @return \Drupal\views\Plugin\views\HandlerBase[] */ public function getHandlers($type) { if (!isset($this->handlers[$type])) { @@ -2406,17 +2409,18 @@ public function renderArea($area, $empty = FALSE) { /** * Determine if the user has access to this display of the view. */ - public function access($account = NULL) { + public function access(AccountInterface $account = NULL) { if (!isset($account)) { $account = \Drupal::currentUser(); } // Full override. - if (user_access('access all views', $account)) { + if ($account->hasPermission('access all views')) { return TRUE; } $plugin = $this->getPlugin('access'); + /** @var \Drupal\views\Plugin\views\access\AccessPluginBase $plugin */ if ($plugin) { return $plugin->access($account); } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php index 283c7cf4e54e992488a2cdc4b3b48316b0b056a5..9ac028ea7aa26eb4cc0fcea787b2410d4b8ba6a6 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php @@ -361,8 +361,9 @@ public function testDestroy() { protected function assertViewDestroy($view) { $reflection = new \ReflectionClass($view); $defaults = $reflection->getDefaultProperties(); - // The storage should remain. + // The storage and user should remain. unset($defaults['storage']); + unset($defaults['user']); foreach ($defaults as $property => $default) { $this->assertIdentical($this->getProtectedProperty($view, $property), $default); diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index f6a0129cd790ec282dababe98aab5afaafc7788a..4b96efe06aebbf494cc9fa81ed89e27133bdd486 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -7,6 +7,7 @@ namespace Drupal\views; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\ViewStorageInterface; use Drupal\Component\Utility\Tags; @@ -406,6 +407,13 @@ class ViewExecutable { ), ); + /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $user; + /** * Should the admin links be shown on the rendered view. * @@ -418,11 +426,14 @@ class ViewExecutable { * * @param \Drupal\views\ViewStorageInterface $storage * The view config entity the actual information is stored on. + * @param \Drupal\Core\Session\AccountInterface $user + * The current user. */ - public function __construct(ViewStorageInterface $storage) { + public function __construct(ViewStorageInterface $storage, AccountInterface $user) { // Reference the storage and the executable to each other. $this->storage = $storage; $this->storage->set('executable', $this); + $this->user = $user; // Add the default css for a view. $this->element['#attached']['library'][] = array('views', 'views.module'); @@ -627,7 +638,7 @@ public function chooseDisplay($displays) { $this->initDisplay(); foreach ($displays as $display_id) { - if ($this->displayHandlers->get($display_id)->access()) { + if ($this->displayHandlers->get($display_id)->access($this->user)) { return $display_id; } } @@ -883,7 +894,7 @@ protected function _initHandler($key, $info) { // Run through and test for accessibility. foreach ($handlers as $id => $handler) { - if (!$handler->access()) { + if (!$handler->access($this->user)) { unset($handlers[$id]); } } @@ -1485,7 +1496,7 @@ public function attachDisplays() { // Find out which other displays attach to the current one. foreach ($this->display_handler->getAttachedDisplays() as $id) { // Create a clone for the attachments to manipulate. 'static' refers to the current class name. - $cloned_view = new static($this->storage); + $cloned_view = new static($this->storage, $this->user); $this->displayHandlers->get($id)->attachTo($cloned_view, $this->current_display); } $this->is_attachment = FALSE; @@ -1528,7 +1539,7 @@ public function access($displays = NULL, $account = NULL) { } if (!$account) { - $account = \Drupal::currentUser(); + $account = $this->user; } // We can't use choose_display() here because that function @@ -1701,6 +1712,18 @@ public function getPath() { return $this->display_handler->getPath(); } + /** + * Gets the current user. + * + * Views plugins can recieve the current user in order to not need dependency + * injection. + * + * @return \Drupal\Core\Session\AccountInterface + */ + public function getUser() { + return $this->user; + } + /** * Creates a duplicate ViewExecutable object. * @@ -1730,9 +1753,10 @@ public function destroy() { $reflection = new \ReflectionClass($this); $defaults = $reflection->getDefaultProperties(); - // The storage should not be reset. This is not generated by the execution - // of a view. + // The external dependencies should not be reset. This is not generated by + // the execution of a view. unset($defaults['storage']); + unset($defaults['user']); foreach ($defaults as $property => $default) { $this->{$property} = $default; } diff --git a/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php b/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php index 5b33f57b97c4f18a4a69c13f00df8e036c20cb35..c6f9828f9b309691873b79ded3637f59fcd05741 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutableFactory.php @@ -7,6 +7,7 @@ namespace Drupal\views; +use Drupal\Core\Session\AccountInterface; use Drupal\views\ViewStorageInterface; /** @@ -14,6 +15,23 @@ */ class ViewExecutableFactory { + /** + * Stores the current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $user; + + /** + * Constructs a new ViewExecutableFactory + * + * @param \Drupal\Core\Session\AccountInterface $user + * The current user. + */ + public function __construct(AccountInterface $user) { + $this->user = $user; + } + /** * Instantiates a ViewExecutable class. * @@ -23,8 +41,8 @@ class ViewExecutableFactory { * @return \Drupal\views\ViewExecutable * A ViewExecutable instance. */ - public static function get(ViewStorageInterface $view) { - return new ViewExecutable($view); + public function get(ViewStorageInterface $view) { + return new ViewExecutable($view, $this->user); } } diff --git a/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php index bd2caed52d02e942975c4d79b2e1134dc8746e16..05cbbaff3024c7f09e80412920ad56c5d6e3b5c2 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php @@ -115,7 +115,7 @@ public function testAccessDeniedView() { ->method('access') ->will($this->returnValue(FALSE)); - $this->executableFactory->staticExpects($this->once()) + $this->executableFactory->expects($this->once()) ->method('get') ->with($view) ->will($this->returnValue($executable)); @@ -162,7 +162,7 @@ protected function setupValidMocks() { ->method('preview') ->will($this->returnValue(array('#markup' => 'View result'))); - $this->executableFactory->staticExpects($this->once()) + $this->executableFactory->expects($this->once()) ->method('get') ->with($view) ->will($this->returnValue($executable)); diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/Block/ViewsBlockTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/Block/ViewsBlockTest.php index bcfd88b7463001c87a9e28f31907de480ca412ef..15d4d6e0605a5cbdc39980854b81e5255ddcfe62 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/Block/ViewsBlockTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/Block/ViewsBlockTest.php @@ -94,8 +94,9 @@ protected function setUp() { ->getMock(); $this->executableFactory = $this->getMockBuilder('Drupal\views\ViewExecutableFactory') + ->disableOriginalConstructor() ->getMock(); - $this->executableFactory->staticExpects($this->any()) + $this->executableFactory->expects($this->any()) ->method('get') ->with($this->view) ->will($this->returnValue($this->executable)); diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/area/ResultTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/area/ResultTest.php index f32f7063eb81765bbd9b4b69b7520ec1ace965ce..8751de054e1d9263a6f7a014d3348a36863124f2 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/area/ResultTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/area/ResultTest.php @@ -51,7 +51,8 @@ public function setUp() { ->method('label') ->will($this->returnValue('ResultTest')); - $this->view = new ViewExecutable($storage); + $user = $this->getMock('Drupal\Core\Session\AccountInterface'); + $this->view = new ViewExecutable($storage, $user); $this->resultHandler = new Result(array(), 'result', array()); $this->resultHandler->view = $this->view; diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php index 43eb50e8a2640fc0a0f464bcff6048970dbc8e75..50028a40a2bc60484f22e88db43bb1f18ba3ba88 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/field/CounterTest.php @@ -80,7 +80,8 @@ protected function setUp() { ); $storage = new View($config, 'view'); - $this->view = $this->getMock('Drupal\views\ViewExecutable', NULL, array($storage)); + $user = $this->getMock('Drupal\Core\Session\AccountInterface'); + $this->view = $this->getMock('Drupal\views\ViewExecutable', NULL, array($storage, $user)); $this->display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase') ->disableOriginalConstructor() diff --git a/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php b/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php index 5bcf07a2421f8b2680bf4e1a21d62e6a7914db76..b5bba9b366b67be95dbf7a522a38e5466e8cc807 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php @@ -87,7 +87,7 @@ public function testPageController() { ->with('default', array()) ->will($this->returnValue(array('#markup' => 'example output'))); - $this->executableFactory->staticExpects($this->any()) + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); @@ -131,7 +131,7 @@ public function testHandleWithArgumentsWithoutOverridden() { ->method('executeDisplay') ->with('page_1', array('test-argument')); - $this->executableFactory->staticExpects($this->any()) + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); @@ -177,7 +177,7 @@ public function testHandleWithArgumentsOnOveriddenRoute() { ->method('executeDisplay') ->with('page_1', array('test-argument')); - $this->executableFactory->staticExpects($this->any()) + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); @@ -227,7 +227,7 @@ public function testHandleWithArgumentsOnOveriddenRouteWithUpcasting() { ->method('executeDisplay') ->with('page_1', array('example_id')); - $this->executableFactory->staticExpects($this->any()) + $this->executableFactory->expects($this->any()) ->method('get') ->with($view) ->will($this->returnValue($executable)); diff --git a/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php b/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php index 650beba4eedcc89848e899a14810a0d352b8e051..6a186917df94430cc1064d98d0b602f9ab0cd735 100644 --- a/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/ViewExecutableUnitTest.php @@ -43,7 +43,8 @@ public function testBuildThemeFunctions() { ); $storage = new View($config, 'view'); - $view = new ViewExecutable($storage); + $user = $this->getMock('Drupal\Core\Session\AccountInterface'); + $view = new ViewExecutable($storage, $user); $expected = array( 'test_hook__test_view', diff --git a/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php b/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php index ee49ab3e38ef8f1e8f3d26df8a0151bdad25c473..9466c0b13fdad051b3bcc53fa69ea64587657e70 100644 --- a/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/ViewsTest.php @@ -30,7 +30,8 @@ protected function setUp() { parent::setUp(); $container = new ContainerBuilder(); - $container->set('views.executable', new ViewExecutableFactory()); + $user = $this->getMock('Drupal\Core\Session\AccountInterface'); + $container->set('views.executable', new ViewExecutableFactory($user)); $this->view = new View(array('id' => 'test_view'), 'view'); diff --git a/core/modules/views/views.services.yml b/core/modules/views/views.services.yml index 201780bf76c6647fd745750baac1e0bed7d0b55b..c8e74828cc26adfa595859817f7a33635c380d8d 100644 --- a/core/modules/views/views.services.yml +++ b/core/modules/views/views.services.yml @@ -64,6 +64,7 @@ services: arguments: ['@views.views_data'] views.executable: class: Drupal\views\ViewExecutableFactory + arguments: ['@current_user'] views.analyzer: class: Drupal\views\Analyzer arguments: ['@module_handler'] diff --git a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php index 12a09849adf9300e2add661d7511f3fd141d0768..e170fc88d5de131cc020b0c0020f7259bb9b896d 100644 --- a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php +++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php @@ -114,7 +114,8 @@ public function testBuildRowEntityList() { ))); $container = new ContainerBuilder(); - $executable_factory = new ViewExecutableFactory(); + $user = $this->getMock('Drupal\Core\Session\AccountInterface'); + $executable_factory = new ViewExecutableFactory($user); $container->set('views.executable', $executable_factory); $container->set('plugin.manager.views.display', $display_manager); $container->set('string_translation', $this->getStringTranslationStub());