diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php index eccd4639c8e13bd495af3991fdf0417d0f333335..618a3c2f29d34b2382b5671d6adcc432cd1d53d0 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php @@ -13,6 +13,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Database\Connection; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -83,11 +84,11 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { // Only grant access to users with the 'access news feeds' permission. - return user_access('access news feeds'); + return $account->hasPermission('access news feeds'); } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php index 4fc69fedcae67be6dd337550f1d7d4380c7ef135..b5272e9c7bbf156b34dce01fae7de7e3810e0fd0 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php @@ -13,6 +13,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -86,11 +87,11 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { // Only grant access to users with the 'access news feeds' permission. - return user_access('access news feeds'); + return $account->hasPermission('access news feeds'); } /** diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index 61bf3a1ecd15c88d90374c9002aeb5ad3ccd5554..2355c00ad23519abe1de1b8a6a5f2d351db00fe5 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -67,7 +67,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A } // If the plugin denies access, then deny access. - if (!$entity->getPlugin()->access()) { + if (!$entity->getPlugin()->access($account)) { return FALSE; } diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index fa603d26a693f66344fb55a8d297a292ea48d4ef..a602ab911802e32103dcd678a8c44bddd931fba4 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -11,6 +11,7 @@ use Drupal\block\BlockInterface; use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\Language; +use Drupal\Core\Session\AccountInterface; /** * Defines a base block implementation that most blocks plugins will extend. @@ -66,7 +67,7 @@ public function setConfigurationValue($key, $value) { /** * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { // By default, the block is visible unless user-configured rules indicate // that it should be hidden. return TRUE; diff --git a/core/modules/block/lib/Drupal/block/BlockPluginInterface.php b/core/modules/block/lib/Drupal/block/BlockPluginInterface.php index b5433e6357975d6790104de49cd1a2bbb15c002c..598dff3d15e56382897ad6309772b9619e4823bc 100644 --- a/core/modules/block/lib/Drupal/block/BlockPluginInterface.php +++ b/core/modules/block/lib/Drupal/block/BlockPluginInterface.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\Core\Session\AccountInterface; /** * Defines the required interface for all block plugins. @@ -27,12 +28,15 @@ interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormIn * This method allows base implementations to add general access restrictions * that should apply to all extending block plugins. * + * @param \Drupal\Core\Session\AccountInterface $account + * The user session for which to check access. + * * @return bool * TRUE if the block should be shown, or FALSE otherwise. * * @see \Drupal\block\BlockAccessController */ - public function access(); + public function access(AccountInterface $account); /** * Builds and returns the renderable array for this block plugin. diff --git a/core/modules/block/tests/modules/block_test/lib/Drupal/block_test/Plugin/Block/TestBlockInstantiation.php b/core/modules/block/tests/modules/block_test/lib/Drupal/block_test/Plugin/Block/TestBlockInstantiation.php index 1d5e947cf96ceccf5b83e96171bc51498d7651b1..e12b07d1d3f44d8178ff55b1194ee9b881932f8c 100644 --- a/core/modules/block/tests/modules/block_test/lib/Drupal/block_test/Plugin/Block/TestBlockInstantiation.php +++ b/core/modules/block/tests/modules/block_test/lib/Drupal/block_test/Plugin/Block/TestBlockInstantiation.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a basic block for testing block instantiation and configuration. @@ -33,8 +34,8 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function access() { - return user_access('access content'); + public function access(AccountInterface $account) { + return $account->hasPermission('access content'); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php b/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php index 10358ae0d6118d9724e14300a9fc7673ad592bc6..150d91a7204c4fe3b14bdc95086c55f90ec7ca35 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Block/RecentCommentsBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Recent comments' block. @@ -31,10 +32,10 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('access comments'); + public function access(AccountInterface $account) { + return $account->hasPermission('access comments'); } /** diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php b/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php index 0f4fff4a78c67ecb7be5afd46f84071db46a5320..c2ad994208edee90783fdeecd8cdb0965279eaf5 100644 --- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php +++ b/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php @@ -8,6 +8,7 @@ namespace Drupal\forum\Plugin\Block; use Drupal\block\BlockBase; +use Drupal\Core\Session\AccountInterface; /** * Provides a base class for Forum blocks. @@ -28,10 +29,10 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('access content'); + public function access(AccountInterface $account) { + return $account->hasPermission('access content'); } /** diff --git a/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php b/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php index 5279dd6b079569e8988b6e950ce63ea87fedc8bb..fab28d861057de4887460423121f3960d66af101 100644 --- a/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php +++ b/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Language switcher' block. @@ -23,9 +24,9 @@ class LanguageBlock extends BlockBase { /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - function access() { + function access(AccountInterface $account) { return language_multilingual(); } diff --git a/core/modules/node/lib/Drupal/node/Plugin/Block/RecentContentBlock.php b/core/modules/node/lib/Drupal/node/Plugin/Block/RecentContentBlock.php index feb93b215134fad53a8af85b18340e94591d692b..92a129d57ac6e8c4492964367c5f934a0cf03b8b 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Block/RecentContentBlock.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Block/RecentContentBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Recent content' block. @@ -31,10 +32,10 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('access content'); + public function access(AccountInterface $account) { + return $account->hasPermission('access content'); } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/Block/SyndicateBlock.php b/core/modules/node/lib/Drupal/node/Plugin/Block/SyndicateBlock.php index 0f4504329bac774e42e260a6c92078351f004041..04ed8b9b95d73d6feaa1625781cffa5985b94d47 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Block/SyndicateBlock.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Block/SyndicateBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Syndicate' block that links to the site's RSS feed. @@ -31,10 +32,10 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('access content'); + public function access(AccountInterface $account) { + return $account->hasPermission('access content'); } /** diff --git a/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php b/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php index 08652bb6b11a1c1c4d3da7e2e4ba653ee1d13b8b..99643e2377ce31daf3c53ba5b3f13594dd33c040 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php +++ b/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php @@ -7,6 +7,7 @@ namespace Drupal\search\Plugin\Block; +use Drupal\Core\Session\AccountInterface; use Drupal\block\BlockBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -22,10 +23,10 @@ class SearchBlock extends BlockBase { /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('search content'); + public function access(AccountInterface $account) { + return $account->hasPermission('search content'); } /** diff --git a/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php index ece4740608320029f966eaf2187691c1101b20d8..659d755153e068469956669384be6d4f2a17141a 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Popular content' block. @@ -53,11 +54,11 @@ public function defaultConfiguration() { ); } - /** - * Overrides \Drupal\block\BlockBase::access(). + /** + * {@inheritdoc} */ - public function access() { - if (\Drupal::currentUser()->hasPermission('access content')) { + public function access(AccountInterface $account) { + if ($account->hasPermission('access content')) { $daytop = $this->configuration['top_day_num']; if (!$daytop || !($result = statistics_title_list('daycount', $daytop)) || !($this->day_list = node_title_list($result, t("Today's:")))) { return FALSE; diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php index 48ad76febed1c558ea71009746d70cbf29f32606..a8c05fe3755f1b6718181cf0723ae50709e57c3b 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php @@ -12,6 +12,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -76,9 +77,9 @@ public static function create(ContainerInterface $container, array $configuratio } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { $this->help = $this->getActiveHelp($this->request); return (bool) $this->help; } diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php index 92f137bdc092605160c6f6407ea6b8d4bc5871f0..c983672bc0ab65fcf530855f427b2d7f3784a0f7 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a generic Menu block. @@ -24,12 +25,12 @@ class SystemMenuBlock extends BlockBase { /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { // @todo Clean up when http://drupal.org/node/1874498 lands. list( , $derivative) = explode(':', $this->getPluginId()); - return ($GLOBALS['user']->isAuthenticated() || in_array($derivative, array('main', 'tools', 'footer'))); + return ($account->isAuthenticated() || in_array($derivative, array('main', 'tools', 'footer'))); } /** diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php index 8106ce383e7c411ac0a4ffd6c1bd92ae9455fc8d..c4f3c4fb0d99768f1a8ddc5db2425c8e412e302a 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php @@ -7,6 +7,7 @@ namespace Drupal\user\Plugin\Block; +use Drupal\Core\Session\AccountInterface; use Drupal\block\BlockBase; /** @@ -20,10 +21,10 @@ class UserLoginBlock extends BlockBase { /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return (!$GLOBALS['user']->id() && !(arg(0) == 'user' && !is_numeric(arg(1)))); + public function access(AccountInterface $account) { + return (!$account->id() && !(arg(0) == 'user' && !is_numeric(arg(1)))); } /** diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php index 71b28e3fe408e3f40e1a305da55495c7e408786d..5a639563a05b244dd8bba689bf8ed1b023c8e031 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a "Who's new" block. @@ -34,10 +35,10 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('access content'); + public function access(AccountInterface $account) { + return $account->hasPermission('access content'); } /** diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php index 7370b7a823b4aff3ad293ef410850a2cfd11f561..d3e26b81005cee2c9d442dc978063610b5992d49 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a "Who's online" block. @@ -38,10 +39,10 @@ public function defaultConfiguration() { } /** - * Overrides \Drupal\block\BlockBase::access(). + * {@inheritdoc} */ - public function access() { - return user_access('access content'); + public function access(AccountInterface $account) { + return $account->hasPermission('access content'); } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlockBase.php b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlockBase.php index 10f5dd2dd1a23f508c4452900917341684587486..e20f146760e257af05be34bf92bb9916e7b0d967 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlockBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlockBase.php @@ -12,6 +12,7 @@ use Drupal\views\ViewExecutableFactory; use Drupal\Core\Entity\EntityStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Session\AccountInterface; /** * Base class for Views block plugins. @@ -79,7 +80,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account) { return $this->view->access($this->displayID); }