diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index d32444f..cf30661 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\block\Plugin\Core\Entity\Block; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; +use Drupal\user\Plugin\Core\Entity\User; /** * Defines a base block implementation that most blocks plugins will extend. @@ -131,7 +132,7 @@ public function blockAccess() { * @see hook_block_access() * @see \Drupal\block\BlockBase::blockAccess() */ - public function access() { + public function access(User $user = NULL) { // If the block-specific access restrictions indicate the block is not // accessible, always deny access. if (!$this->blockAccess()) { @@ -139,7 +140,11 @@ public function access() { } // Otherwise, check for other access restrictions. - global $user; + if (!$user) { + // For consistency, load actual User entity. + // $GLOBALS['user'] is a stdClass. + $user = user_load($GLOBALS['user']->uid); + } // Deny access to disabled blocks. if (!$this->entity->get('status')) { diff --git a/core/modules/block/lib/Drupal/block/BlockInterface.php b/core/modules/block/lib/Drupal/block/BlockInterface.php index 65bdee3..be8e3ca 100644 --- a/core/modules/block/lib/Drupal/block/BlockInterface.php +++ b/core/modules/block/lib/Drupal/block/BlockInterface.php @@ -7,6 +7,8 @@ namespace Drupal\block; +use Drupal\user\Plugin\Core\Entity\User; + /** * Defines the required interface for all block plugins. * @@ -42,7 +44,7 @@ public function settings(); * * @see \Drupal\block\BlockAccessController */ - public function access(); + public function access(User $user = NULL); /** * Constructs the block configuration form.