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 c9fe040..c672ede 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides an 'Aggregator category' block for the latest items in a category. @@ -36,9 +37,9 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 4b002a2..d5b3d3d 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides an 'Aggregator feed' block with the latest items from the feed. @@ -36,9 +37,9 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 a4827e5..d28919b 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -30,7 +30,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 f1217c0..4e41071 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. @@ -75,7 +76,7 @@ public function setConfigurationValue($key, $value) { /** * {@inheritdoc} */ - public function access() { + public function access(AccountInterface $account = null) { // 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 5f353a4..83f64dc 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. @@ -39,12 +40,14 @@ public function settings(); * 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 Account Interface. * @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 4c28638..184107a 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a basic block for testing block instantiation and configuration. @@ -34,8 +35,8 @@ public function settings() { /** * {@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 cf442db..2bc2ec3 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Recent comments' block. @@ -34,8 +35,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 cbdfc79..7b9f4ee 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. @@ -30,8 +31,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 fa8a249..77353d1 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Language switcher' block. @@ -26,7 +27,7 @@ class LanguageBlock extends BlockBase { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 8144161..269ef29 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Recent content' block. @@ -34,8 +35,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 1440a48..9b20d78 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Syndicate' block that links to the site's RSS feed. @@ -34,8 +35,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 b692e5e..29623c6 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; @@ -45,8 +46,8 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 d11412e..b34d375 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'Popular content' block. @@ -57,8 +58,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - public function access() { - if (user_access('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 c19a575..87383d4 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'System Help' block. @@ -32,7 +33,7 @@ class SystemHelpBlock extends BlockBase { /** * Overrides \Drupal\block\BlockBase::access(). */ - public function access() { + public function access(AccountInterface $account = null) { $this->help = menu_get_active_help(); 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 1daf4bf..8972bb6 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'System Menu' block. @@ -26,10 +27,10 @@ class SystemMenuBlock extends BlockBase { /** * Overrides \Drupal\block\BlockBase::access(). */ - public function access() { + public function access(AccountInterface $account) { // @todo The 'Tools' menu should be available to anonymous users. list($plugin, $derivative) = explode(':', $this->getPluginId()); - return ($GLOBALS['user']->isAuthenticated() || in_array($derivative, array('menu-main', 'menu-tools', 'menu-footer'))); + return ($account->isAuthenticated() || in_array($derivative, array('menu-main', 'menu-tools', 'menu-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 ab4401c..13246e1 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Drupal\Core\Session\AccountInterface; /** * Provides a 'User login' block. @@ -78,8 +79,8 @@ public static function create(ContainerInterface $container, array $configuratio /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 26be5ba..fb7360c 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a "Who's new" block. @@ -37,8 +38,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 3f5b0b2..601c36d 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\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Provides a "Who's online" block. @@ -41,8 +42,8 @@ public function settings() { /** * Overrides \Drupal\block\BlockBase::access(). */ - 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 b90b3e6..6b1f6a9 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); }