Issue #2283969 by tim.plunkett: Add a protected BlockBase::blockAccess() to contain plugin-specific logic.
parent
5f6ca548ac
commit
12317b75fd
|
@ -100,7 +100,7 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
// Only grant access to users with the 'access news feeds' permission.
|
||||
return $account->hasPermission('access news feeds');
|
||||
}
|
||||
|
|
|
@ -112,8 +112,23 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
// By default, the block is visible unless user-configured rules indicate
|
||||
// that it should be hidden.
|
||||
// @todo Move block visibility here in https://drupal.org/node/2278541.
|
||||
return $this->blockAccess($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the block should be shown.
|
||||
*
|
||||
* @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 self::access()
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
// By default, the block is visible.
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestBlockInstantiation extends BlockBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $account->hasPermission('access content');
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ abstract class ForumBlockBase extends BlockBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $account->hasPermission('access content');
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $this->languageManager->isMultilingual();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class SyndicateBlock extends BlockBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $account->hasPermission('access content');
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class SearchBlock extends BlockBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $account->hasPermission('search content');
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class StatisticsPopularBlock extends BlockBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(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:")))) {
|
||||
|
|
|
@ -78,7 +78,7 @@ class SystemHelpBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
$this->help = $this->getActiveHelp($this->request);
|
||||
return (bool) $this->help;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class RedirectFormBlock extends BlockBase implements ContainerFactoryPluginInter
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class UserLoginBlock extends BlockBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
$route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
|
||||
return ($account->isAnonymous() && !in_array($route_name, array('user.register', 'user.login', 'user.logout')));
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ abstract class ViewsBlockBase extends BlockBase implements ContainerFactoryPlugi
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account) {
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return $this->view->access($this->displayID);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue