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 eccd463..618a3c2 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 4fc69fe..b5272e9 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 61bf3a1..2355c00 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 579e841..9df546f 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 b5433e6..598dff3 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 @@ * 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 1d5e947..e12b07d 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 10358ae..150d91a 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 0f4fff4..c2ad994 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 5279dd6..fab28d8 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 feb93b2..92a129d 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 0f45043..04ed8b9 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 c977ba1..eefce11 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php +++ b/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php @@ -12,6 +12,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\search\Form\SearchBlockForm; +use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -42,10 +43,10 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi } /** - * 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 ece4740..659d755 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 48ad76f..a8c05fe 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 92f137b..c983672 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 b3de132..cb9a8ee 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php @@ -14,6 +14,7 @@ use Drupal\user\Form\UserLoginForm; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'User login' block. @@ -74,10 +75,10 @@ public static function create(ContainerInterface $container, array $configuratio } /** - * 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 71b28e3..5a63956 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 7370b7a..d3e26b8 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 10f5dd2..e20f146 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); }