Commit 49ac6300 authored by alexpott's avatar alexpott

Issue #1951386 by benjy, theduke, andypost, tim.plunkett: Fixed Extend...

Issue #1951386 by benjy, theduke, andypost, tim.plunkett: Fixed Extend BlockPluginInterface::access to allow passing in an account.
parent 37b3d5ca
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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.
......
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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();
}
......
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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')));
}
/**
......
......@@ -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))));
}
/**
......
......@@ -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');
}
/**
......
......@@ -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');
}
/**
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment